Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You can actually replace that foreach loop and the if statement above it with code similar to this answer this answer to determine if two dictionaries are equal:

You can actually replace that foreach loop and the if statement above it with code similar to this answer to determine if two dictionaries are equal:

You can actually replace that foreach loop and the if statement above it with code similar to this answer to determine if two dictionaries are equal:

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Edit 2: k2snowman69 pointed out k2snowman69 pointed out that you could sacrifice some speed for less memory usage by avoiding dictionaries and instead sorting both strings and comparing each character in sequence. Now I have an excuse to post this solution, which not only does that, but is shorter and a lot more readable:

Edit 2: k2snowman69 pointed out that you could sacrifice some speed for less memory usage by avoiding dictionaries and instead sorting both strings and comparing each character in sequence. Now I have an excuse to post this solution, which not only does that, but is shorter and a lot more readable:

Edit 2: k2snowman69 pointed out that you could sacrifice some speed for less memory usage by avoiding dictionaries and instead sorting both strings and comparing each character in sequence. Now I have an excuse to post this solution, which not only does that, but is shorter and a lot more readable:

Added a solution that sorts then compares
Source Link

Edit 2:k2snowman69 pointed out that you could sacrifice some speed for less memory usage by avoiding dictionaries and instead sorting both strings and comparing each character in sequence. Now I have an excuse to post this solution, which not only does that, but is shorter and a lot more readable:

public static bool AreStringsAnagrams(string a, string b)
{
 return a.Count() == b.Count() && a.OrderBy(x => x).SequenceEqual(b.OrderBy(x => x));
}

Edit 2:k2snowman69 pointed out that you could sacrifice some speed for less memory usage by avoiding dictionaries and instead sorting both strings and comparing each character in sequence. Now I have an excuse to post this solution, which not only does that, but is shorter and a lot more readable:

public static bool AreStringsAnagrams(string a, string b)
{
 return a.Count() == b.Count() && a.OrderBy(x => x).SequenceEqual(b.OrderBy(x => x));
}
Added a check right away for differing string lengths.
Source Link
Loading
Source Link
Loading
lang-cs

AltStyle によって変換されたページ (->オリジナル) /