Why i always get a weired question?


  • 0
    E

    Hi:

        ArrayList<String> expand(String crt, Set<String> dict) {
        	        ArrayList<String> expansion = new ArrayList<String>();
                    char[] str=crt.toCharArray();
        	        for (int i = 0; i < str.length; i++) {
        	            for (char ch = 'a'; ch <= 'z'; ch++) {
        	                if (ch != crt.charAt(i)) {
        	                    String expanded = crt.substring(0, i) + ch
        	                            + crt.substring(i + 1);
        	                  ////////////str[i]=ch;
        	                   ////////////////// String expanded=new String(str); 
    ///////////////////if I wrote like this two lines, would get nothing in the outpur, and if I wrote the previous line, it would work perfectly, why is that? 
        	                    if (dict.contains(expanded)) {
        	                        expansion.add(expanded);
        	                    }
        	                }
        	            }
        	        }
        	        return expansion;
        	    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.