MCPcopy
hub / github.com/qiyuangong/leetcode / maxWidthRamp

Method maxWidthRamp

java/962_Maximum_Width_Ramp.java:3–18  ·  view source on GitHub ↗
(int[] A)

Source from the content-addressed store, hash-verified

1import java.awt.Point;
2class Solution {
3 public int maxWidthRamp(int[] A) {
4 int N = A.length;
5 Integer[] B = new Integer[N];
6 for (int i = 0; i < N; ++i)
7 B[i] = i;
8 // Sort index based on value
9 Arrays.sort(B, (i, j) -> ((Integer) A[i]).compareTo(A[j]));
10
11 int ans = 0;
12 int m = N;
13 for (int i: B) {
14 ans = Math.max(ans, i - m);
15 m = Math.min(m, i);
16 }
17 return ans;
18 }
19
20 /*public int maxWidthRamp(int[] A) {
21 int N = A.length;

Callers

nothing calls this directly

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected