-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathAnagramFree.cpp
47 lines (42 loc) · 1.19 KB
/
AnagramFree.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <string>
#include <cstring>
#include <vector>
using namespace std;
class AnagramFree {
public:
bool isAnagram(string& a, string& b) {
int ca[256];
memset(ca, 0, sizeof(ca));
int cb[256];
memset(cb, 0, sizeof(cb));
if (a.size() != b.size())
return false;
for (int i = 0; i < a.size(); ++i) {
ca[(int)a[i]]++;
cb[(int)b[i]]++;
}
for (int i = 0; i < 256; ++i) {
if (ca[i] != cb[i])
return false;
}
return true;
}
int getMaximumSubset(vector <string> S) {
bool t[55];
memset(t, 0, sizeof(t));
for (int i = 0; i < S.size(); ++i) {
for (int j = i+1; j < S.size(); ++j) {
if (isAnagram(S[i], S[j])) {
t[j] = true;
}
}
}
int result = 0;
for (int i = 0; i < S.size(); ++i) {
if (t[i] == false) {
++result;
}
}
return result;
}
};