File tree 5 files changed +45
-0
lines changed
algorithms/ContainsDuplicate
5 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ All solutions will be accepted!
46
46
| 231| [ Power Of Two] ( https://leetcode-cn.com/problems/power-of-two/description/ ) | [ java/py/js] ( ./algorithms/PowerOfTwo ) | Easy|
47
47
| 38| [ Count And Say] ( https://leetcode-cn.com/problems/count-and-say/description/ ) | [ java/py/js] ( ./algorithms/CountAndSay ) | Easy|
48
48
| 383| [ Ransom Note] ( https://leetcode-cn.com/problems/ransom-note/description/ ) | [ java/py/js] ( ./algorithms/RansomNote ) | Easy|
49
+ | 217| [ Contains Duplicate] ( https://leetcode-cn.com/problems/contains-duplicate/description/ ) | [ java/py/js] ( ./algorithms/ContainsDuplicate ) | Easy|
49
50
50
51
# Database
51
52
| #| Title| Solution| Difficulty|
Original file line number Diff line number Diff line change
1
+ # Contains Duplicate
2
+ This problem is easy to solve by hashmap
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ public boolean containsDuplicate (int [] nums ) {
3
+ Map <Integer , Boolean > intMap = new HashMap <Integer , Boolean >();
4
+ for (int num : nums ) {
5
+ if (intMap .get (num ) == null ) {
6
+ intMap .put (num , true );
7
+ } else {
8
+ return true ;
9
+ }
10
+ }
11
+ return false ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {boolean }
4
+ */
5
+ var containsDuplicate = function ( nums ) {
6
+ let intMap = { }
7
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
8
+ let num = nums [ i ]
9
+ if ( intMap [ num ] === undefined ) {
10
+ intMap [ num ] = true
11
+ } else {
12
+ return true
13
+ }
14
+ }
15
+ return false
16
+ } ;
Original file line number Diff line number Diff line change
1
+ class Solution (object ):
2
+ def containsDuplicate (self , nums ):
3
+ """
4
+ :type nums: List[int]
5
+ :rtype: bool
6
+ """
7
+ int_map = {}
8
+ for num in nums :
9
+ if int_map .get (num ) == None :
10
+ int_map [num ] = True
11
+ else :
12
+ return True
13
+ return False
You can’t perform that action at this time.
0 commit comments