Skip to content

Commit 5ae6bd7

Browse files
committed
feat: contains-duplicate
1 parent f291ae8 commit 5ae6bd7

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

contains-duplicate/minji-go.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
/*
2-
Problem: https://leetcode.com/problems/contains-duplicate/
3-
Description: return true if any value appears at least twice in the array
4-
Concept: Array, Hash Table, Sorting
5-
Time Complexity: O(n), Runtime: 10ms
6-
Space Complexity: O(n), Memory: 58.6MB
7-
*/
8-
import java.util.HashSet;
9-
import java.util.Set;
1+
/**
2+
<a href="https://leetcode.com/problems/contains-duplicate/">week01-1.contains-duplicate</a>
3+
<li> Description: return true if any value appears at least twice in the array </li>
4+
<li> Concept: Array, Hash Table, Sorting </li>
5+
<li> Time Complexity: O(n), Runtime: 11ms </li>
6+
<li> Space Complexity: O(n), Memory: 59.27MB </li>
7+
*/
108

119
class Solution {
10+
Set<Integer> set = new HashSet<>();
11+
1212
public boolean containsDuplicate(int[] nums) {
13-
Set<Integer> count = new HashSet<>();
14-
boolean answer = false;
15-
for(int num : nums){
16-
if(count.contains(num)) {
17-
answer = true;
18-
break;
19-
}
20-
count.add(num);
21-
}
22-
return answer;
13+
return !Arrays.stream(nums).allMatch(set::add);
2314
}
2415
}

0 commit comments

Comments
 (0)