Java solution in 5ms


  • 0
    G

    class Solution {
    public char findTheDifference(String s, String t) {
    int sum = 0;
    char[] a = s.toCharArray();
    char[] b = t.toCharArray();
    for(int i =0; i < a.length; i++ ) sum ^= (a[i]^b[i]);
    sum = sum ^ b[b.length-1];
    return (char)sum;
    }
    }


Log in to reply
 

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