leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1006.cpp (443B)
0 class Solution {
1 static int other(int n) {
2 if (n <= 0) return 0;
3 int res = n;
4 if (n > 1) res *= n - 1;
5 if (n > 2) res /= n - 2;
6 if (n > 3) res -= n - 3;
7 return res + other(n - 4);
8 }
10 public:
11 int clumsy(int n) const {
12 int res = n;
13 if (n > 1) res *= n - 1;
14 if (n > 2) res /= n - 2;
15 if (n > 3) res += n - 3;
16 return res - other(n - 4);
17 }
18 };