-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path242.cs
More file actions
33 lines (29 loc) · 819 Bytes
/
Copy path242.cs
File metadata and controls
33 lines (29 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Solution
{
public bool IsAnagram(string s, string t)
{
if (s.Length != t.Length) return false;
var dictionary_Of_S = new Dictionary<char, int>();
foreach (var letter in s)
{
if (dictionary_Of_S.ContainsKey(letter)){
dictionary_Of_S[letter]++;
}
else {
dictionary_Of_S.Add(letter, 1);
}
}
foreach (var letter in t)
{
if (dictionary_Of_S.ContainsKey(letter)){
dictionary_Of_S[letter]--;
if (dictionary_Of_S[letter] == 0){
dictionary_Of_S.Remove(letter);
}
}
else {
return false;}
}
return dictionary_Of_S.Count == 0;
}
}