Skip to content

Latest commit

 

History

History
17 lines (16 loc) · 366 Bytes

File metadata and controls

17 lines (16 loc) · 366 Bytes
  • 计算两个字符串每个字符的数量,如果所有字符数量都相等则是异位词
class Solution {
 public:
  bool isAnagram(string s, string t) {
    vector<int> v(26);
    for (auto& x : s) {
      ++v[x - 'a'];
    }
    for (auto& x : t) {
      --v[x - 'a'];
    }
    return all_of(begin(v), end(v), [](int x) { return !x; });
  }
};