JAVA simple solution


  • 1
    public char findTheDifference(String s, String t) {
            int[] arr = new int[26]; //lower case ASCII 97-122
            for(int i=0; i<s.length(); i++){
                arr[s.charAt(i)-97]--;
                arr[t.charAt(i)-97]++;
            }
            arr[t.charAt(s.length())-97]++;
            
            for(int i=0; i<arr.length; i++){
                if(arr[i] > 0) return (char)(i+97);
            }
            return '\0';
        }
    

Log in to reply
 

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