Java 4 lines O(1) space, simple


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

Log in to reply
 

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