We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 31c3c01 commit 6282936Copy full SHA for 6282936
1006.Clumsy-Factorial.py
@@ -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
30
+ tmp -= (i - 3)
31
32
33
+ res = tmp
34
+ is_first = False
35
36
+ res -= tmp
37
38
+ return res
39
0 commit comments