Compare commits

...

2 Commits

2 changed files with 30 additions and 8 deletions
@@ -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,21 +38,36 @@ 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:
s = set()
for x in nums:
if x in s:
return True
s.add(x)
return False
#+end_src
** TODO C++
** DONE C++
#+begin_src cpp
#include <vector>
#include <set>
class Solution {
public:
bool containsDuplicate(vector<int>& nums) {
bool containsDuplicate(std::vector<int>& nums) {
std::set<int> s;
for (int x: nums) {
if (s.contains(x)) {
return true;
}
s.insert(x);
}
return false;
}
};
#+end_src
+9 -2
View File
@@ -21,8 +21,15 @@ Source: [[https://neetcode.io/roadmap][neetcode.io/roadmap]]
Notes: [[file:dsa/arrays-hashing/0217-contains-duplicate.org]]
** TODO 0242. Valid Anagram :easy:
:PROPERTIES:
:LEETCODE: [[https://leetcode.com/problems/valid-anagram/][Problem]]
:CPP: [[https://github.com/neetcode-gh/leetcode/blob/main/cpp/0242-valid-anagram.cpp][Solution]]
:LEETCODE: [[https://lclass Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
s = set()
for x in nums:
if x in s:
return True
s.add(x)
return False
.com/neetcode-gh/leetcode/blob/main/cpp/0242-valid-anagram.cpp][Solution]]
:PYTHON: [[https://github.com/neetcode-gh/leetcode/blob/main/python/0242-valid-anagram.py][Solution]]
:VIDEO: [[https://youtube.com/watch?v=9UtInBqnCgA][Watch]]
:END: