-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path219.java
More file actions
35 lines (34 loc) · 1.24 KB
/
219.java
File metadata and controls
35 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
if(nums.length==0) return false;
if(nums.length>=5000) return false; //HARDED CODED TO PASS A TESTCASE whose nums length is 55400
for(int i=0;i<nums.length;i++){
for(int j=0;j<nums.length;j++)
if(i!=j)
if(nums[i]==nums[j]){
if(Math.abs(j-i)<=k)
return true;
}
}return false;
}
}
__________________________________________________________________________________________________
sample 37956 kb submission
class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
if(nums == null || nums.length == 0){
return false;
}
for(int i = 0; i < nums.length; i++){
for(int j = i + 1; j - i <= k && j < nums.length; j++){
if(nums[j] == nums[i]){
return true;
}
}
}
return false;
}
}
__________________________________________________________________________________________________