-
Notifications
You must be signed in to change notification settings - Fork 0
/
367.py
39 lines (30 loc) · 841 Bytes
/
367.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = ['"wuyadong" <[email protected]>']
class Solution(object):
def isPerfectSquare(self, num):
"""
:type num: int
:rtype: bool
"""
start = 1
end = num
while start <= end:
mid = (start+end)/2
if start+1 == end:
if end * end == num or start * start == num:
return True
else:
return False
if mid * mid > num:
end = mid
elif mid * mid < num:
start = mid
else:
return True
if start * start == num:
return True
else:
return False
if __name__ == "__main__":
print Solution().isPerfectSquare(2)