File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author :- Rishabh Jain <contact@rishabh1403.com>
3+ Solution for :- https://leetcode.com/problems/contains-duplicate/
4+ blog for this code :- https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-valid-anagram
5+ youtube video :- https://youtu.be/7z25qqUCOUE
6+ */
7+
8+
9+ var containsDuplicate = function ( nums ) {
10+ const set = new Set ( nums ) ;
11+
12+ return set . size !== nums . length
13+ } ;
Original file line number Diff line number Diff line change 1+ /*
2+ Author :- Rishabh Jain <contact@rishabh1403.com>
3+ Solution for :- https://leetcode.com/problems/contains-duplicate-ii/
4+ blog for this code :- https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-valid-anagram
5+ youtube video :- https://youtu.be/7z25qqUCOUE
6+ */
7+
8+
9+ var containsNearbyDuplicate = function ( nums , k ) {
10+ const map = new Map ( ) ;
11+
12+ for ( let i = 0 ; i < nums . length ; i ++ ) {
13+ if ( map . has ( nums [ i ] ) ) {
14+ const j = map . get ( nums [ i ] ) ;
15+ if ( Math . abs ( i - j ) <= k ) {
16+ return true ;
17+ } else {
18+ map . set ( nums [ i ] , i ) ;
19+ }
20+ } else {
21+ map . set ( nums [ i ] , i ) ;
22+ }
23+ }
24+
25+ return false ;
26+ } ;
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ Solutions of all the questions from Leetcode in JavaScript.
2626
2727- 167.Two Sum-II - [ Question] ( https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/101-200/167-two-sum-ii.js ) | [ Blog] ( https://rishabh1403.com/leetcode-solution-of-two-sum-ii-in-javascript ) | [ Youtube Video] ( https://www.youtube.com/watch?v=MjxN8HIzIRc )
2828
29+ - 217.Contains Duplicate - [ Question] ( https://leetcode.com/problems/contains-duplicate/ ) | [ Source Code] ( ) | [ Blog] ( ) | [ Youtube Video] ( )
30+
31+ - 219.Contains Duplicate II - [ Question] ( https://leetcode.com/problems/contains-duplicate-ii/ ) | [ Source Code] ( ) | [ Blog] ( ) | [ Youtube Video] ( )
32+
2933- 242.Valid Anagram - [ Question] ( https://leetcode.com/problems/valid-anagram/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/201-300/242-valid-anagram.js ) | [ Blog] ( https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-valid-anagram ) | [ Youtube Video] ( https://youtu.be/7z25qqUCOUE )
3034
3135- 268.Missing Number - [ Question] ( https://leetcode.com/problems/missing-number/ ) | [ Source Code] ( https://github.com/rishabh1403/leetcode-javascript-solutions/blob/master/201-300/268-missing-number.js ) | [ Blog] ( https://rishabh1403.com/posts/coding/leetcode/2020/03/leetcode-missing-number ) | [ Youtube Video] ( https://youtu.be/I6AUMvi13fc )
You can’t perform that action at this time.
0 commit comments