my simple solution using comparison.


  • 0
    C
    public class Solution {
        public char findTheDifference(String s, String t) {
            int slen = s.length();
            int tlen = t.length();
            char[] s1 = s.toCharArray();
            char[] t1 = t.toCharArray(); 
            Arrays.sort(s1);
            Arrays.sort(t1);
            int index = 0;
            while(index<slen){
                if(s1[index] !=t1[index]){
                    return t1[index];
                }
                else{
                    index++;
                }
            }
            
            return t1[index];
        }
    }
    

Log in to reply
 

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