File tree 3 files changed +55
-0
lines changed
solution/1400-1499/1447.Simplified Fractions
3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,26 @@ class Solution {
82
82
}
83
83
```
84
84
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
+
85
105
### ** C++**
86
106
87
107
``` cpp
Original file line number Diff line number Diff line change @@ -90,6 +90,26 @@ class Solution {
90
90
}
91
91
```
92
92
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
+
93
113
### ** C++**
94
114
95
115
``` cpp
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments