public static int ladderLength(String start, String end, Set<String> dict) {
        // write your code here
        String s=start, e=end;
        if (s.equals(e))
            return 1;
        Queue<String> q=new ArrayDeque<>();
        dict.add(s);
        q.offer(e);
        Map<String, Integer> dist=new HashMap<>();
        dist.put(e,0);
        int rel=1;
        while (!q.isEmpty()) {
            ++rel;
            for (int n=q.size(), i=0;i<n;++i) {
                String t=q.poll();
                int cd=dist.get(t);
                char[]ts=t.toCharArray();
                for (int j=0;j<ts.length;++j) {
                    char pc=ts[j];
                    for (char z='a';z<='z';++z) {
                        ts[j]=z;
                        String key=new String(ts);
                        if (dict.contains(key)) {
                            Integer nd=dist.get(key);
                            if (nd==null) {
                                dist.put(key,cd+1);
                                q.offer(key);
                            }
                            if (key.equals(s))
                                return rel;
                        }
                    }
                    ts[j]=pc;
                }
            }
        }
        return 0;
    }