-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3200. Maximum Height of a Triangle
50 lines (50 loc) · 1.17 KB
/
3200. Maximum Height of a Triangle
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
class Solution {
public int maxHeightOfTriangle(int red, int blue) {
int count1=0,count2=0;
int r1=red,b1=blue;
int r2=red,b2=blue;
boolean bl=true;
while(r1>=0 && b1>=0) {
count1++;
if (bl) {
if(b1>= count1) {
b1-= count1;
}
else{
break;
}
}
else{
if(r1 >= count1) {
r1 -= count1;
}
else{
break;
}
}
bl = !bl;
}
boolean re=true;
while (r2 >= 0 && b2 >= 0) {
count2++;
if (re) {
if(r2>=count2) {
r2-=count2;
}
else{
break;
}
}
else{
if(b2 >= count2) {
b2 -= count2;
}
else{
break;
}
}
re = !re;
}
return Math.max(count1-1,count2-1);
}
}