c# solution using XOR


  • 0
    D
    public class Solution {
        public char FindTheDifference(string s, string t){
            char result=' ';
            char[] xor = new char[s.Length];
            for(int i=0;i<s.Length;i++)
            {
                xor[i] = (char)(s[i]^t[i]);
            }
            for(int j=0;j<xor.Length;j++)
            {
                result = (char)(result^xor[j]);
            }
            return (char)((result^t[t.Length-1])+32);
        }
    }
    

Log in to reply
 

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