FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

LeetCode242 add second fun · feixiangcode/algorithm@4dffeae · GitHub

Commit 4dffeae

Browse files
committed
LeetCode242 add second fun
1 parent 9fb1f50 commit 4dffeae

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎Week_02/id_131/LeetCode_242_131.cpp‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,27 @@ class Solution {
2121
}
2222
return true;
2323
}
24+
25+
bool isAnagramB(string s, string t)
26+
{
27+
if(s.size() != t.size()) {
28+
return false;
29+
}
30+
31+
// 假设字符串只包含小写字母
32+
int alphabet[26] = {0};
33+
34+
// 统计字符串s中小写字母出现的次数
35+
for(int indexStr = 0; indexStr < s.size(); ++indexStr){
36+
alphabet[alphabet[indexStr]-'a']++;
37+
}
38+
39+
// 长度固定,所有字母出现的次数必须都相同
40+
for(int indexStr = 0; indexStr < t.size(); ++indexStr){
41+
if(--alphabet[alphabet[indexStr] - 'a'] < 0)
42+
return false;
43+
}
44+
45+
return true;
46+
}
2447
};

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL