Skip to content

Commit c17a760

Browse files
committed
2020-02-05
1 parent 7931778 commit c17a760

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

0633.平方数之和/0633-平方数之和.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@ def judgeSquareSum(self, c):
44
:type c: int
55
:rtype: bool
66
"""
7-
8-
if c == (int(c ** 0.5) ** 2):
9-
return True
10-
11-
lo, hi = 0, int(c ** 0.5)
12-
while(lo <= hi):
13-
s = lo ** 2 + hi ** 2
14-
if s == c:
7+
for i in range(int(c ** 0.5) + 1):
8+
t = c - i ** 2
9+
s = int (t ** 0.5)
10+
if t == s ** 2:
1511
return True
16-
elif s > c:
17-
hi -= 1
18-
else:
19-
lo += 1
20-
return False
21-
12+
return False if c else True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution(object):
2+
def findDerangement(self, n):
3+
"""
4+
:type n: int
5+
:rtype: int
6+
"""
7+
res = 0
8+
for i in range(n + 1):
9+
res = (i * res + (-1) ** i) % (10 ** 9 + 7)
10+
return res

0 commit comments

Comments
 (0)