-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountBadPairs.java
51 lines (50 loc) · 1.24 KB
/
CountBadPairs.java
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public class CountBadPairs {
public static void main(String[] args) {
int[] nums = {4,1,3,3};
System.out.println(countBadPairs(nums));
}
static long countBadPairs(int[] nums)
{
long count=0;
// for (int i = 0, k = nums.length-1; i < k; i++) {
// for (int j = i+1; j < nums.length; j++) {
// long a = j-i;
// long b = nums[j] - nums[i];
// if(i<j && a!=b)
// {
// count++;
// }
// }
// }
int i=0,j=0;
while(i< nums.length && j< nums.length)
{
long a = j-i;
long b = nums[j] - nums[i];
if(i<j && a!=b)
{
count++;
j++;
if(j==nums.length)
{
j=0;
i++;
continue;
}
continue;
}
else
{
j++;
if(j==nums.length)
{
j=0;
i++;
continue;
}
continue;
}
}
return count;
}
}