Skip to content

Commit

Permalink
feat: add solutions to lc problem: No.0179
Browse files Browse the repository at this point in the history
  • Loading branch information
rain84 committed Sep 18, 2024
1 parent 06eab06 commit dee7885
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
26 changes: 26 additions & 0 deletions solution/0100-0199/0179.Largest Number/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,32 @@ public class Solution {
}
```

#### TypeScript

```ts
function largestNumber(nums: number[]): string {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}
```

#### JavaScript

```js
function largestNumber(nums) {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
26 changes: 26 additions & 0 deletions solution/0100-0199/0179.Largest Number/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,32 @@ public class Solution {
}
```

#### TypeScript

```ts
function largestNumber(nums: number[]): string {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}
```

#### JavaScript

```js
function largestNumber(nums) {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
8 changes: 8 additions & 0 deletions solution/0100-0199/0179.Largest Number/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function largestNumber(nums) {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}
8 changes: 8 additions & 0 deletions solution/0100-0199/0179.Largest Number/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function largestNumber(nums: number[]): string {
nums.sort((a, b) => {
const [ab, ba] = [String(a) + String(b), String(b) + String(a)];
return +ba - +ab;
});

return nums[0] ? nums.join('') : '0';
}

0 comments on commit dee7885

Please sign in to comment.