Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Anagrams String
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Collections; namespace Rextester { public class Program { public static void Main(string[] args) { var word1= "hehehehehe"; var word2 = "hhhhheeeeee"; Console.Out.Write(IsAnagrams(word1, word2)); } public static bool IsAnagrams(string word1, string word2) { if (word1 == null || word2 == null) { return false; } if (word1.Length != word2.Length) { return false; } if (word1 == word2) { return true; } var word1Hash = BuildDict(word1); var word2Hash = BuildDict(word2); foreach (var pair1 in word1Hash) { var key = pair1.Key; if (word2Hash.ContainsKey(key)) { if (word2Hash[key] == pair1.Value) return true; } } return false; } public static Dictionary<char, int> BuildDict(string word) { var hash = new Dictionary<char, int>(); foreach (var c in word) { if (hash.ContainsKey(c)) { hash[c] +=1 ; } else { hash[c] = 1 ; } } return hash; } } }
run
|
edit
|
history
|
help
0
ffsfsfsfsfsferwfehtyjrvgjb
Print 2D Array
*271*271#
case2
Charan GR
Math Course: Remainders
Merge two array
Decimal test
a6
Selection sort