29 lines
853 B
Python
29 lines
853 B
Python
class Solution:
|
|
def maxHeightOfTriangle(self, red: int, blue: int) -> int:
|
|
# Let's try starting with both colors and take the maximum result
|
|
return max(self.tryHeight(red, blue), self.tryHeight(blue, red))
|
|
|
|
def tryHeight(self, color1: int, color2: int) -> int:
|
|
height = 0
|
|
row = 1
|
|
|
|
# Keep alternating colors
|
|
while True:
|
|
# Try to use color1 for odd rows
|
|
if row % 2 == 1:
|
|
if color1 >= row:
|
|
color1 -= row
|
|
height += 1
|
|
else:
|
|
break
|
|
# Try to use color2 for even rows
|
|
else:
|
|
if color2 >= row:
|
|
color2 -= row
|
|
height += 1
|
|
else:
|
|
break
|
|
row += 1
|
|
|
|
return height
|