Skip to content

Commit abc367d

Browse files
committed
1006 added.
1 parent 282a646 commit abc367d

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(B)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(B main.cpp)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// Source : https://leetcode.com/problems/clumsy-factorial/
2+
/// Author : liuyubobobo
3+
/// Time : 2019-03-09
4+
5+
#include <iostream>
6+
7+
using namespace std;
8+
9+
10+
/// Simulation
11+
/// Time Complexity: O(n)
12+
/// Space Complexity: O(1)
13+
class Solution {
14+
public:
15+
int clumsy(int N) {
16+
17+
if(N == 1) return 1;
18+
if(N == 2) return 2;
19+
if(N == 3) return 6;
20+
21+
int res = N * (N - 1) / (N - 2);
22+
N -= 3;
23+
while(N >= 4){
24+
res += N - (N - 1) * (N - 2) / (N - 3);
25+
N -= 4;
26+
}
27+
return res + !!N;
28+
}
29+
};
30+
31+
32+
int main() {
33+
34+
cout << Solution().clumsy(4) << endl;
35+
cout << Solution().clumsy(10) << endl;
36+
37+
return 0;
38+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,4 +672,5 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
672672
| 1003 | [Check If Word Is Valid After Substitutions](https://leetcode.com/problems/check-if-word-is-valid-after-substitutions/) | [] | [C++](1003-Check-If-Word-Is-Valid-After-Substitutions/cpp-1003/) | | |
673673
| 1004 | [Max Consecutive Ones III](https://leetcode.com/problems/max-consecutive-ones-iii/) | [] | [C++](1004-Max-Consecutive-Ones-III/cpp-1004/) | | |
674674
| 1005 | [Maximize Sum Of Array After K Negations](https://leetcode.com/problems/maximize-sum-of-array-after-k-negations/) | [] | [C++](1005-Maximize-Sum-Of-Array-After-K-Negations/cpp-1005/) | | |
675+
| 1006 | [Clumsy Factorial](https://leetcode.com/problems/clumsy-factorial/) | [] | [C++](1006-Clumsy-Factorial/cpp-1006/) | | |
675676
| | | | | | |

0 commit comments

Comments
 (0)