Skip to content

Instantly share code, notes, and snippets.

@u8989332
Created October 13, 2020 14:10
Show Gist options
  • Save u8989332/e874eae0653407bc39a00af03f7fc148 to your computer and use it in GitHub Desktop.
Save u8989332/e874eae0653407bc39a00af03f7fc148 to your computer and use it in GitHub Desktop.
LeetCode - 242 Valid Anagram
using System;
using System.Collections.Generic;
namespace LeetCode242
{
public class Solution {
public bool IsAnagram(string s, string t) {
List<int> sCheck = new List<int>();
List<int> tCheck = new List<int>();
for(int i = 0 ; i < 26;++i){
sCheck.Add(0);
tCheck.Add(0);
}
for(int i = 0 ; i < s.Length;++i){
sCheck[s[i] - 'a']++;
}
for(int i = 0 ; i < t.Length;++i){
tCheck[t[i] - 'a']++;
}
bool isSame = true;
for(int i = 0 ; i < 26;++i){
if(sCheck[i] != tCheck[i]){
isSame = false;
break;
}
}
return isSame;
}
}
public class Program
{
public static void Main()
{
Solution sol = new Solution();
Console.WriteLine(sol.IsAnagram("anagram", "nagaram"));
Console.Read();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment