From fc6e664ff9739f86e0ed245d6221482579136888 Mon Sep 17 00:00:00 2001 From: Wong Ding Feng Date: Mon, 1 Jun 2026 17:35:55 +0800 Subject: [PATCH] solve: 0217 Contains Duplicate (C++ set approach) --- .../0217-contains-duplicate.org | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/org/study_deck_02/dsa/arrays-hashing/0217-contains-duplicate.org b/org/study_deck_02/dsa/arrays-hashing/0217-contains-duplicate.org index 5957e9e..6800f74 100644 --- a/org/study_deck_02/dsa/arrays-hashing/0217-contains-duplicate.org +++ b/org/study_deck_02/dsa/arrays-hashing/0217-contains-duplicate.org @@ -1,5 +1,5 @@ #+PROPERTY: STUDY_DECK_02 -* TODO 0217. Contains Duplicate :easy: +* DONE 0217. Contains Duplicate :easy: :PROPERTIES: :NEETCODE: [[file:../../roadmap.org::*0217. Contains Duplicate][0217. Contains Duplicate]] :END: @@ -38,10 +38,10 @@ All elements are distinct. - ~-10^{9} <= nums[i] <= 10^{9}~ -** TODO Approach +** DONE Approach Write your approach here. -** TODO Python +** DONE Python #+begin_src python class Solution: def containsDuplicate(self, nums: List[int]) -> bool: @@ -53,12 +53,21 @@ class Solution: return False #+end_src -** TODO C++ +** DONE C++ #+begin_src cpp +#include +#include class Solution { public: - bool containsDuplicate(vector& nums) { - + bool containsDuplicate(std::vector& nums) { + std::set s; + for (int x: nums) { + if (s.contains(x)) { + return true; + } + s.insert(x); } + return false; + } }; #+end_src