Leetcode 1048 Solution
This article provides solution to leetcode question 1048 (clumsy-factorial)
Access this page by simply typing in "lcs 1048" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/clumsy-factorial
Solution
class Solution:
def clumsy(self, N: int) -> int:
ans = 0
n = N
while n >= 1:
tmp = n
if n >= 2:
tmp *= n - 1
if n >= 3:
tmp //= n - 2
if n < N:
tmp = -tmp
if n >= 4:
tmp += n - 3
ans += tmp
n -= 4
return ans