Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3ae053d

Browse files
authored
feat: add solutions to lc problem: No.0179 (doocs#3532)
1 parent 06eab06 commit 3ae053d

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

‎solution/0100-0199/0179.Largest Number/README.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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 -->

‎solution/0100-0199/0179.Largest Number/README_EN.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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 -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /