File tree 3 files changed +18
-3
lines changed
solution/1400-1499/1447.Simplified Fractions
3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -97,8 +97,13 @@ function simplifiedFractions(n: number): string[] {
97
97
return ans ;
98
98
};
99
99
100
+ // a < b
100
101
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 ;
102
107
}
103
108
```
104
109
Original file line number Diff line number Diff line change @@ -105,8 +105,13 @@ function simplifiedFractions(n: number): string[] {
105
105
return ans ;
106
106
};
107
107
108
+ // a < b
108
109
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 ;
110
115
}
111
116
```
112
117
Original file line number Diff line number Diff line change @@ -10,6 +10,11 @@ function simplifiedFractions(n: number): string[] {
10
10
return ans ;
11
11
} ;
12
12
13
+ // a < b
13
14
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 ;
15
20
}
You can’t perform that action at this time.
0 commit comments