what's wrong with my codes? I run it correctly in Eclipse.


  • 0
    W

    public class Solution {
    public char findTheDifference(String s, String t) {
    for(int i = 0;i<s.length();i++)
    {
    String z = t.replaceAll(s.substring(i,i+1),"");
    t = z;
    }
    char b = t.charAt(0);
    return b;
    }
    }


  • 1
    S

    Your solution will work (though not optimally, or nothing close to to that) only if all the characters were unique. That is not the case for this question. Try "abcde" and "abcdee". Since you replace all the "e" with "" in t, you end up with an empty string.


  • 0
    W

    @sasantv Thank you and you get the point.


Log in to reply
 

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