| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,4 +21,27 @@ class Solution { | |||
| 21 | 21 | } | |
| 22 | 22 | return true; | |
| 23 | 23 | } | |
| 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 | + } | ||
| 24 | 47 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments