Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 179. Largest Number

Posted on 2021-04-13 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
const largestNumber = (nums) => {
const ans = nums.map(a => a.toString())
// .sort((a, b) => (a + b) - (b + a))
// .reduce((prev, curr) => curr + prev);
.sort((a, b) => (b + a) - (a + b))
.join('')
return ans[0] == '0' ? '0' : ans;
};
# Sort
LeetCode 264. Ugly Number II
LeetCode 783. Minimum Distance Between BST Nodes
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%