/
158.cpp
38 lines (38 loc) · 984 Bytes
/
158.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
/*
* =====================================================================================
*
* Filename: 158.cpp
*
* Description:
*
* Version: 1.0
* Created: 06/26/16 12:40:44
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/
class Solution {
public:
/**
* @param s: The first string
* @param b: The second string
* @return true or false
*/
bool anagram(string s, string t) {
vector<int> ascii(128, 0);
for (string::size_type c_iter = 0; c_iter != s.size(); c_iter++) {
ascii[int(s[c_iter])]++;
}
for(string::size_type c_iter = 0; c_iter != t.size(); c_iter++){
if(-- ascii[int(t[c_iter])] < 0){
return false;
exit(0);
}
}
return true;
}
};