Accepted C# sol


  • 0
    S
    public class Solution {
    public bool IsAnagram(string s, string t) {
        if(s.Length != t.Length)
            return false;
         
        Dictionary<char,int> dict = new Dictionary<char,int>();
        for(int j=0; j<t.Length; j++)
        {
            if(dict.ContainsKey(t[j]))
            {
                dict[t[j]]++;
            }
            else
            {
                dict.Add(t[j],1);
            }
        }
    
        for(int i=0; i<t.Length; i++)
        {
            if(dict.ContainsKey(s[i]))
            {
                if(dict[s[i]]>0)
                {
                    dict[s[i]]--;
                }
                else
                    return false;
            }
            else
                return false;
        }
        return true;
        
    }
    

    }


Log in to reply
 

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