Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Create: 367-Valid-Perfect-Square.py
  • Loading branch information
UdayGarg committed Oct 4, 2022
commit 5cb6c667e152e25e91c1a96a46753a586ddab577
21 changes: 21 additions & 0 deletions python/367-Valid-Perfect-Square.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution:
def isPerfectSquare(self, num: int) -> bool:
for i in range(1, num+1):
if i * i == num:
return True
if i* i > num:
return False



def isPerfectSquare_2(self, num: int) -> bool:
l ,r = 1, num
while l <= r:
mid = (l +r) // 2
if mid * mid > num:
r = mid - 1
elif mid * mid < num:
l = mid + 1
else:
return True
return False