Cadenza5566

2026/03/23

[LeetCode] 217 Contains Duplicate

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class Solution {
public:
  bool containsDuplicate(vector<int>& nums) {
    std::unordered_set<int> set;
    for (auto &num : nums) {
      if (set.count(num)) 
        return true;
      else 
        set.insert(num);
    } 
    return false;
  }
};
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.