-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path242.cpp
More file actions
27 lines (26 loc) · 695 Bytes
/
Copy path242.cpp
File metadata and controls
27 lines (26 loc) · 695 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
class Solution {
public:
bool isAnagram(string s, string t) {
quickSort(s, 0, s.size() - 1);
quickSort(t, 0, t.size() - 1);
return s == t;
}
void quickSort(string &s, int head, int tail) {
int i = head, j = tail;
if (i >= j) return;
char std = s[i];
while (i < j) {
while (j > i && (int) s[j] >= (int) std)
--j;
if (j > i)
s[i] = s[j];
while (i < j && (int) s[i] <= (int) std)
++i;
if (i < j)
s[j] = s[i];
}
s[i] = std;
quickSort(s, head, i - 1);
quickSort(s, i + 1, tail);
}
};