Skip to content

Commit 723c78a

Browse files
committed
1447 solved.
1 parent 20299bd commit 723c78a

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-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.16)
2+
project(cpp_1447)
3+
4+
set(CMAKE_CXX_STANDARD 14)
5+
6+
add_executable(cpp_1447 main.cpp)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// Source : https://leetcode.com/problems/simplified-fractions/
2+
/// Author : liuyubobobo
3+
/// Time : 2020-05-16
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <unordered_set>
8+
9+
using namespace std;
10+
11+
12+
/// Brute Force + GCD + HashSet
13+
/// Time Complexity: O(n^2)
14+
/// Space Complexity: O(n^2)
15+
class Solution {
16+
public:
17+
vector<string> simplifiedFractions(int n) {
18+
19+
unordered_set<string> res;
20+
for(int d = 2; d <= n; d ++)
21+
for(int i = 1; i < d; i ++){
22+
int g = gcd(d, i);
23+
res.insert(to_string(i / g) + "/" + to_string(d / g));
24+
}
25+
return vector<string>(res.begin(), res.end());
26+
}
27+
28+
private:
29+
int gcd(int a, int b){
30+
return b == 0 ? a : gcd(b, a % b);
31+
}
32+
};
33+
34+
int main() {
35+
36+
return 0;
37+
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
10471047
| 1444 | [Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza/) | [] | [C++](1444-Number-of-Ways-of-Cutting-a-Pizza/cpp-1444/) | | |
10481048
| | | | | | |
10491049
| 1446 | [Consecutive Characters](https://leetcode.com/problems/consecutive-characters/) | [] | [C++](1446-Consecutive-Characters/cpp-1446/) | | |
1050+
| 1447 | [Simplified Fractions](https://leetcode.com/problems/simplified-fractions/) | [] | [C++](1447-Simplified-Fractions/cpp-1447/) | | |
10501051
| | | | | | |
10511052

10521053
## 力扣中文站比赛

0 commit comments

Comments
 (0)