Skip to content

Commit

Permalink
changed isAnagram algorythm to other logic
Browse files Browse the repository at this point in the history
this is my first commit to a public repo, so i don't know if i'm doing it right
  • Loading branch information
itai192 committed Sep 25, 2020
1 parent 504140e commit 63b2fa3
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions Algorithms/Strings/Permutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,12 @@ public static bool IsAnargram(string source, string other)
return true;

int len = source.Length;
// Hash set which will contains all the characters present in input source.
var hashSetSourceChars = new HashSet<char>();
var hashSetOtherChars = new HashSet<char>();
for (int i = 0; i < len; i++)
for(int i = 0; i<len;i++)
{
hashSetSourceChars.Add(source[i]);
hashSetOtherChars.Add(other[i]);
}
for (int i = 0; i < len; i++)
{
// Inputs are not Anargram if characers from *other are not present in *source.
if (!hashSetSourceChars.Contains(other[i])) return false;
if (!hashSetOtherChars.Contains(source[i])) return false;
int index = other.IndexOf(source[i]);
if(index==-1)
return false;
other.Remove(index);
}
return true;
}
Expand Down

0 comments on commit 63b2fa3

Please sign in to comment.