Skip to content

Commit f958d36

Browse files
authored
Merge pull request #1432 from ivan1016017/october22
adding algo
2 parents 893dfa2 + 6527174 commit f958d36

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List, Union, Collection, Mapping, Optional
2+
from abc import ABC, abstractmethod
3+
4+
class Solution:
5+
def mySqrt(self, x: int) -> int:
6+
7+
left, right = 0, x
8+
9+
while left <= right:
10+
11+
mid = (left + right)//2
12+
13+
if mid**2 < x:
14+
left = mid + 1
15+
elif mid**2 > x:
16+
right = mid - 1
17+
else:
18+
return mid
19+
20+
return min(left, right)

tests/test_150_questions_round_20/test_sqrtx_round_20.py

Whitespace-only changes.

0 commit comments

Comments
 (0)