File tree Expand file tree Collapse file tree 4 files changed +68
-0
lines changed
solution/0100-0199/0179.Largest Number Expand file tree Collapse file tree 4 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,32 @@ public class Solution {
183183}
184184```
185185
186+ #### TypeScript
187+
188+ ``` ts
189+ function largestNumber(nums : number []): string {
190+ nums .sort ((a , b ) => {
191+ const [ab, ba] = [String (a ) + String (b ), String (b ) + String (a )];
192+ return + ba - + ab ;
193+ });
194+
195+ return nums [0 ] ? nums .join (' ' ) : ' 0' ;
196+ }
197+ ```
198+
199+ #### JavaScript
200+
201+ ``` js
202+ function largestNumber (nums ) {
203+ nums .sort ((a , b ) => {
204+ const [ab , ba ] = [String (a) + String (b), String (b) + String (a)];
205+ return + ba - + ab;
206+ });
207+
208+ return nums[0 ] ? nums .join (' ' ) : ' 0' ;
209+ }
210+ ```
211+
186212<!-- tabs: end -->
187213
188214<!-- solution: end -->
Original file line number Diff line number Diff line change @@ -180,6 +180,32 @@ public class Solution {
180180}
181181```
182182
183+ #### TypeScript
184+
185+ ``` ts
186+ function largestNumber(nums : number []): string {
187+ nums .sort ((a , b ) => {
188+ const [ab, ba] = [String (a ) + String (b ), String (b ) + String (a )];
189+ return + ba - + ab ;
190+ });
191+
192+ return nums [0 ] ? nums .join (' ' ) : ' 0' ;
193+ }
194+ ```
195+
196+ #### JavaScript
197+
198+ ``` js
199+ function largestNumber (nums ) {
200+ nums .sort ((a , b ) => {
201+ const [ab , ba ] = [String (a) + String (b), String (b) + String (a)];
202+ return + ba - + ab;
203+ });
204+
205+ return nums[0 ] ? nums .join (' ' ) : ' 0' ;
206+ }
207+ ```
208+
183209<!-- tabs: end -->
184210
185211<!-- solution: end -->
Original file line number Diff line number Diff line change 1+ function largestNumber ( nums ) {
2+ nums . sort ( ( a , b ) => {
3+ const [ ab , ba ] = [ String ( a ) + String ( b ) , String ( b ) + String ( a ) ] ;
4+ return + ba - + ab ;
5+ } ) ;
6+
7+ return nums [ 0 ] ? nums . join ( '' ) : '0' ;
8+ }
Original file line number Diff line number Diff line change 1+ function largestNumber ( nums : number [ ] ) : string {
2+ nums . sort ( ( a , b ) => {
3+ const [ ab , ba ] = [ String ( a ) + String ( b ) , String ( b ) + String ( a ) ] ;
4+ return + ba - + ab ;
5+ } ) ;
6+
7+ return nums [ 0 ] ? nums . join ( '' ) : '0' ;
8+ }
You can’t perform that action at this time.
0 commit comments