Files
leetcode/69-sqrtx/69-sqrtx.py
T

11 lines
257 B
Python

class Solution:
def mySqrt(self, x: int) -> int:
nextOdd = 1
# Represent x as a sum of odd numbers
while x >= nextOdd:
x -= nextOdd
nextOdd += 2
return int((nextOdd - 1) / 2)