2 short Java answers


  • 0
    Y
        public char findTheDifference(String s, String t) {
            int c = t.charAt(s.length());
            for(int i=0; i<s.length(); ++i)
                c+=t.charAt(i) - s.charAt(i);
            return (char)c;
        }
    

    Bit manipulation:

        public char findTheDifference(String s, String t) {
            int c=t.charAt(s.length());
            for(int i=0; i<s.length(); ++i)
                c^=t.charAt(i) ^ s.charAt(i);
            return (char)c;
        }
    

Log in to reply
 

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