Cadenza5566

2026/03/25

[LeetCode] 242 Valid Anagram

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class Solution {
public:
  bool isAnagram(string s, string t) {
    if (s.length() != t.length())
      return false;
      
    unordered_map<char, int> chrMap;
    for (auto &c : s)
      chrMap[c]++;

    for (auto &c : t) {
      if (chrMap.find(c) == chrMap.end() || chrMap[c] == 0)
        return false;
      chrMap[c]--;
    }
    return true;
  }
};
Labels: LeetCode
較新的文章 較舊的文章 首頁

網誌存檔

  • ▼  2026 (98)
    • ►  6月 (2)
    • ►  5月 (34)
    • ►  4月 (30)
    • ▼  3月 (23)
      • [LeetCode] 1143 Longest Common Subsequence
      • [LeetCode] 98 Validate Binary Search Tree
      • [LeetCode] 39 Combination Sum
      • [LeetCode] 572 Subtree of Another Tree
      • [LeetCode] 338 Counting Bits
      • [LeetCode] 242 Valid Anagram
      • [LeetCode] 226 Invert Binary Tree
      • [LeetCode] 217 Contains Duplicate
      • [LeetCode] 125 Valid Palindrome
      • [LeetCode] 121 Best Time to Buy and Sell Stock
      • [LeetCode] 104 Maximum Depth of Binary Tree
      • [LeetCode] 100 Same Tree
      • [LeetCode] 191 Number of 1 Bits
      • [LeetCode] 70 Climbing Stairs
      • [LeetCode] 190 Reverse Bits
      • [LeetCode ] 20 Valid Parentheses
      • [LeetCode] 268 Missing Number
      • [LeetCode] 23 Merge k Sorted Lists
      • [Leetcode] 15 3Sum
      • [LeetCode] 54 Spiral Matrix
      • [LeetCode] 300 Longest Increasing Subsequence
      • [LeetCode] 322 Coin Change
      • [LeetCode] 3 Longest Substring Without Repeating C...
    • ►  2月 (9)
頂尖企業主題. 技術提供:Blogger.