Skip to content

Commit 26635db

Browse files
committed
feat: add ts solution to lc problem: No.1447
No.1447.Simplified Fractions
1 parent aadfad1 commit 26635db

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/1400-1499/1447.Simplified Fractions/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,26 @@ class Solution {
8282
}
8383
```
8484

85+
### **TypeScript**
86+
87+
```ts
88+
function simplifiedFractions(n: number): string[] {
89+
let ans: Array<string> = [];
90+
for (let j = 2; j <= n; j++) {
91+
for (let i = 1; i < j; i++) {
92+
if (gcd(i, j) == 1) {
93+
ans.push(`${i}/${j}`);
94+
}
95+
}
96+
}
97+
return ans;
98+
};
99+
100+
function gcd(a: number, b: number): number {
101+
return a == 0 ? b : gcd(b % a, a);
102+
}
103+
```
104+
85105
### **C++**
86106

87107
```cpp

solution/1400-1499/1447.Simplified Fractions/README_EN.md

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,26 @@ class Solution {
9090
}
9191
```
9292

93+
### **TypeScript**
94+
95+
```ts
96+
function simplifiedFractions(n: number): string[] {
97+
let ans: Array<string> = [];
98+
for (let j = 2; j <= n; j++) {
99+
for (let i = 1; i < j; i++) {
100+
if (gcd(i, j) == 1) {
101+
ans.push(`${i}/${j}`);
102+
}
103+
}
104+
}
105+
return ans;
106+
};
107+
108+
function gcd(a: number, b: number): number {
109+
return a == 0 ? b : gcd(b % a, a);
110+
}
111+
```
112+
93113
### **C++**
94114

95115
```cpp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function simplifiedFractions(n: number): string[] {
2+
let ans: Array<string> = [];
3+
for (let j = 2; j <= n; j++) {
4+
for (let i = 1; i < j; i++) {
5+
if (gcd(i, j) == 1) {
6+
ans.push(`${i}/${j}`);
7+
}
8+
}
9+
}
10+
return ans;
11+
};
12+
13+
function gcd(a: number, b: number): number {
14+
return a == 0 ? b : gcd(b % a, a);
15+
}

0 commit comments

Comments
 (0)