public int ladderLength(String start, String end, HashSet<String> dict) {
        HashSet<String> visited = new HashSet<String>();
        LinkedList<String> queue = new LinkedList<String>();

        int level = 1;
        queue.offer(start);
        queue.offer(null);

        while(!queue.isEmpty()){
            String cur = queue.poll();
            if(cur == null){
                ++level;
                if(queue.isEmpty()) break;
                cur = queue.poll();
                queue.offer(null);
            }
            char[] cs = cur.toCharArray();
            for(char c = 'a'; c <= 'z'; ++c){
                for(int i = 0; i < cur.length(); ++i){
                    char tmp = cs[i];
                    cs[i] = c;
                    String str = new String(cs);
                    if(str.equals(end)) return level+1;
                    if(!visited.contains(str) && dict.contains(str)){
                        queue.offer(str);
                        visited.add(str);
                    }
                    cs[i] = tmp;
                }
            }
        }
        return 0;
    }