3469. Maximum Height of a Triangle
My accepted Python solution to LeetCode problem 3469, Maximum Height of a Triangle, running in 28ms.
- Difficulty: Easy
- Python
- Runtime 28ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 28ms, memory 17.3MB, accepted 2025-12-29.
class Solution:
def maxHeightOfTriangle(self, red: int, blue: int) -> int:
def calc_height(first, second):
height = 0
row = 1
while True:
if row % 2 == 1:
if first >= row:
first -= row
height += 1
else:
break
else:
if second >= row:
second -= row
height += 1
else:
break
row += 1
return height
return max(calc_height(red, blue), calc_height(blue, red))