-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutationString.cs
More file actions
33 lines (28 loc) · 910 Bytes
/
PermutationString.cs
File metadata and controls
33 lines (28 loc) · 910 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
namespace DA.Algorithms.Strings
{
public static class PermutationString
{
/// <summary>
/// Check if two strings are permutation of each other.
/// </summary>
public static bool isPermutation (string source, string assumptionSource)
{
int[] counter = new int[256];
if (assumptionSource.Length != source.Length)
return false;
for (int i = 0; i < 256; i++)
counter[i] = 0;
for (int i = 0; i < source.Length; i++)
{
char character = source[i];
++counter[character];
character = assumptionSource[i];
--counter[character];
}
for (int i = 0; i < source.Length; i++)
if (counter[i] != 0)
return false;
return true;
}
}
}