Compare commits
2 Commits
cf158eafdf
...
fc6e664ff9
| Author | SHA1 | Date | |
|---|---|---|---|
| fc6e664ff9 | |||
| 7659303fb0 |
@@ -1,5 +1,5 @@
|
|||||||
#+PROPERTY: STUDY_DECK_02
|
#+PROPERTY: STUDY_DECK_02
|
||||||
* TODO 0217. Contains Duplicate :easy:
|
* DONE 0217. Contains Duplicate :easy:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:NEETCODE: [[file:../../roadmap.org::*0217. Contains Duplicate][0217. Contains Duplicate]]
|
:NEETCODE: [[file:../../roadmap.org::*0217. Contains Duplicate][0217. Contains Duplicate]]
|
||||||
:END:
|
:END:
|
||||||
@@ -38,21 +38,36 @@ All elements are distinct.
|
|||||||
|
|
||||||
- ~-10^{9} <= nums[i] <= 10^{9}~
|
- ~-10^{9} <= nums[i] <= 10^{9}~
|
||||||
|
|
||||||
** TODO Approach
|
** DONE Approach
|
||||||
Write your approach here.
|
Write your approach here.
|
||||||
|
|
||||||
** TODO Python
|
** DONE Python
|
||||||
#+begin_src python
|
#+begin_src python
|
||||||
class Solution:
|
class Solution:
|
||||||
def containsDuplicate(self, nums: List[int]) -> bool:
|
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
|
#+end_src
|
||||||
|
|
||||||
** TODO C++
|
** DONE C++
|
||||||
#+begin_src cpp
|
#+begin_src cpp
|
||||||
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
class Solution {
|
class Solution {
|
||||||
public:
|
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
|
#+end_src
|
||||||
|
|||||||
@@ -21,8 +21,15 @@ Source: [[https://neetcode.io/roadmap][neetcode.io/roadmap]]
|
|||||||
Notes: [[file:dsa/arrays-hashing/0217-contains-duplicate.org]]
|
Notes: [[file:dsa/arrays-hashing/0217-contains-duplicate.org]]
|
||||||
** TODO 0242. Valid Anagram :easy:
|
** TODO 0242. Valid Anagram :easy:
|
||||||
:PROPERTIES:
|
:PROPERTIES:
|
||||||
:LEETCODE: [[https://leetcode.com/problems/valid-anagram/][Problem]]
|
:LEETCODE: [[https://lclass Solution:
|
||||||
:CPP: [[https://github.com/neetcode-gh/leetcode/blob/main/cpp/0242-valid-anagram.cpp][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]]
|
:PYTHON: [[https://github.com/neetcode-gh/leetcode/blob/main/python/0242-valid-anagram.py][Solution]]
|
||||||
:VIDEO: [[https://youtube.com/watch?v=9UtInBqnCgA][Watch]]
|
:VIDEO: [[https://youtube.com/watch?v=9UtInBqnCgA][Watch]]
|
||||||
:END:
|
:END:
|
||||||
|
|||||||
Reference in New Issue
Block a user