Skip to content

Commit 75c8987

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

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ function simplifiedFractions(n: number): string[] {
9797
return ans;
9898
};
9999

100+
// a < b
100101
function gcd(a: number, b: number): number {
101-
return a == 0 ? b : gcd(b % a, a);
102+
if (a > b) [a, b] = [b, a];
103+
while (a) {
104+
[a, b] = [b % a, a];
105+
}
106+
return b;
102107
}
103108
```
104109

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ function simplifiedFractions(n: number): string[] {
105105
return ans;
106106
};
107107

108+
// a < b
108109
function gcd(a: number, b: number): number {
109-
return a == 0 ? b : gcd(b % a, a);
110+
if (a > b) [a, b] = [b, a];
111+
while (a) {
112+
[a, b] = [b % a, a];
113+
}
114+
return b;
110115
}
111116
```
112117

solution/1400-1499/1447.Simplified Fractions/Solution.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ function simplifiedFractions(n: number): string[] {
1010
return ans;
1111
};
1212

13+
// a < b
1314
function gcd(a: number, b: number): number {
14-
return a == 0 ? b : gcd(b % a, a);
15+
if (a > b) [a, b] = [b, a];
16+
while (a) {
17+
[a, b] = [b % a, a];
18+
}
19+
return b;
1520
}

0 commit comments

Comments
 (0)