-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_3200.java
32 lines (30 loc) · 954 Bytes
/
_3200.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
package com.fishercoder.solutions.fourththousand;
public class _3200 {
public static class Solution1 {
public int maxHeightOfTriangle(int red, int blue) {
return Math.max(getHeight(red, blue), getHeight(blue, red));
}
private int getHeight(int first, int second) {
int height = 1;
boolean useFirst = true;
while (first > 0 || second > 0) {
if (useFirst) {
if (first >= height) {
first -= height;
} else {
break;
}
} else {
if (second >= height) {
second -= height;
} else {
break;
}
}
height++;
useFirst = !useFirst;
}
return height - 1;
}
}
}