This commit is contained in:
2025-06-20 11:27:53 +08:00
parent 3b805a6422
commit 003eb24c77
6 changed files with 238 additions and 1 deletions

28
leetcode_py/3200.py Normal file
View File

@@ -0,0 +1,28 @@
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