Leetcode49字母异位词分组

代码:

这题好像写麻烦了

class Solution {
    public List> groupAnagrams(String[] strs) {
        int n = strs.length;
        List> res = new ArrayList<>();
        UnionFind uf = new UnionFind(n);
        for(int i=0;i list = new ArrayList<>();
            for(int j=0;j0){
                res.add(list);
            }
        }
        return res;
    }
    
}
class UnionFind{
    int[] parent;
    public UnionFind(int n){
        parent = new int[n];
        for(int i=0;i

你可能感兴趣的:(算法)