Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1401 from loczek/179-Largest-Number
Browse files Browse the repository at this point in the history
Create: 179-Largest-Number.ts
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents ca378f5 + 790d820 commit 97c4a11
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions typescript/179-Largest-Number.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function largestNumber(nums: number[]): string {
const strings = nums.map((num) => String(num));

function compare(s1: string, s2: string) {
if (s1 + s2 > s2 + s1) {
return -1;
} else {
return 1;
}
}

const res = strings.sort(compare).join('');
return res.charAt(0) === '0' ? '0' : res;
}

0 comments on commit 97c4a11

Please sign in to comment.