forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_755.java
35 lines (33 loc) · 1.03 KB
/
_755.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
package com.fishercoder.solutions;
public class _755 {
public static class Solution1 {
public int[] pourWater(int[] heights, int V, int K) {
int index;
while (V > 0) {
index = K;
for (int i = K - 1; i >= 0; i--) {
if (heights[i] > heights[index]) {
break;
} else if (heights[i] < heights[index]) {
index = i;
}
}
if (index != K) {
heights[index]++;
V--;
continue;
}
for (int i = K + 1; i < heights.length; i++) {
if (heights[i] > heights[index]) {
break;
} else if (heights[i] < heights[index]) {
index = i;
}
}
heights[index]++;
V--;
}
return heights;
}
}
}