java easy sort solution


  • 0
    H
        public char findTheDifference(String s, String t) {
            char[] s_charArray = s.toCharArray();
            char[] t_charArray = t.toCharArray();
            Arrays.sort(s_charArray);
            Arrays.sort(t_charArray);
            int i=0;
            int j=0;
            while(i<s_charArray.length){
                if(s_charArray[i]!=t_charArray[j])
                    return t_charArray[j];
                i++;j++;
            }
            return t_charArray[t.length()-1];
        }
    

Log in to reply
 

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