Skip to content

Commit 6282936

Browse files
committed
feat(leetcode): add No.1006
1 parent 31c3c01 commit 6282936

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

1006.Clumsy-Factorial.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# https://leetcode.com/problems/clumsy-factorial/
2+
# Medium (53.74%)
3+
# Total Accepted: 2,548
4+
# Total Submissions: 4,741
5+
# beats 100.0% of python submissions
6+
7+
8+
class Solution(object):
9+
def clumsy(self, N):
10+
"""
11+
:type N: int
12+
:rtype: int
13+
"""
14+
res = 0
15+
is_first = True
16+
17+
for i in xrange(N, 0, -4):
18+
tmp = i
19+
for j in xrange(1, 4):
20+
if j - i == 0:
21+
break
22+
if j == 1:
23+
tmp *= (i - 1)
24+
elif j == 2:
25+
tmp /= (i - 2)
26+
else:
27+
if is_first:
28+
tmp += (i - 3)
29+
else:
30+
tmp -= (i - 3)
31+
32+
if is_first:
33+
res = tmp
34+
is_first = False
35+
else:
36+
res -= tmp
37+
38+
return res
39+

0 commit comments

Comments
 (0)