forked from DengWangBao/Leetcode-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
25 lines (20 loc) · 581 Bytes
/
Main.java
File metadata and controls
25 lines (20 loc) · 581 Bytes
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
public class Main {
public static class Solution {
int reversePairs(int[] arr, int m) {
int pairs = 0;
for (int i = m - 1, j = arr.length - 1; j >= m; j--) {
for ( ; i >= 0 && arr[i] > arr[j]; i--);
pairs += m - 1 - i;
}
return pairs;
}
}
public static void main(String[] args) {
Solution s = new Solution();
int[] arr = {
1, 4, 8, 9, 2, 3, 6, 7
};
int n = s.reversePairs(arr, 4);
System.out.println(n);
}
}