Fast and Easy to Understand Java Solution


  • 0
    A

    Every character is just an ASCII value, so keep a running total of the difference in their values. At the end, return the difference as a char.

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

Log in to reply
 

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