From 58bd7d0e5affb3e6895c2b60473258d7b2ebecf8 Mon Sep 17 00:00:00 2001 From: u-siop Date: Sat, 7 Mar 2026 13:53:05 +0000 Subject: [PATCH 1/2] u-siop: contains-duplicate solution --- contains-duplicate/u-siop.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 contains-duplicate/u-siop.cpp diff --git a/contains-duplicate/u-siop.cpp b/contains-duplicate/u-siop.cpp new file mode 100644 index 0000000000..0bd81cf937 --- /dev/null +++ b/contains-duplicate/u-siop.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + bool containsDuplicate(vector& nums) { + // instinct : sort the array and check all the array whether duplicate or not + // time complexity : NlogN(sort) + N(check all the array) + // space complexity : 1 + + // how do we, in real world, judge there is a duplicated element, definitely need a reference( another data strucrue) to check + + unordered_map seen; // using hash map for updating, already have seen the element + + for (const auto& i : nums) { + if (seen[i] >= 1) + return true; + seen[i] = true; + } + + return false; + } +}; \ No newline at end of file From df862dded44c0c91392e1d425b0deef8723afaf9 Mon Sep 17 00:00:00 2001 From: u-siop Date: Sat, 7 Mar 2026 14:11:22 +0000 Subject: [PATCH 2/2] u-siop: add EOF --- contains-duplicate/u-siop.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/u-siop.cpp b/contains-duplicate/u-siop.cpp index 0bd81cf937..a03f78453a 100644 --- a/contains-duplicate/u-siop.cpp +++ b/contains-duplicate/u-siop.cpp @@ -17,4 +17,4 @@ class Solution { return false; } -}; \ No newline at end of file +};