Constant space O(1) C# solution


  • 0
    S
    public class Solution {
        public char FindTheDifference(string s, string t) {
            var cArr = new int[26];
            foreach(var c in s)
            {
                cArr[c-'a']++;
            }
            char res = ' ';
            foreach(var c in t)
            {
                if(--cArr[c-'a'] < 0)
                {
                    res = c;
                    break;
                }
            }
            return res;
        }
    }
    

Log in to reply
 

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