Skip to content

Commit 42bcda5

Browse files
committed
add solution of contains-duplicate
1 parent f291ae8 commit 42bcda5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
class Solution {
3+
public boolean containsDuplicate(int[] nums) {
4+
/**
5+
avg : O(NlogN)
6+
worst : O(N^2)
7+
*/
8+
Arrays.sort(nums);
9+
10+
for (int i = 1; i < nums.length; i++) {
11+
if (nums[i-1] == nums[i]) return true;
12+
}
13+
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)