Hi, this is Shunchi!

  • Home

  • Tags0

  • Archives267

  • Categories0

  • Curricula

  • DSA

  • LeetCode_Notes

  • Interviews

  • General

  • Resume

179. Largest Number

Posted on 2020-05-23 | Edited on 2021-01-22

https://leetcode.com/problems/largest-number/

Explanation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public String largestNumber(int[] nums) {
if(nums==null||nums.length==0) return "";
int len=nums.length;
String[] strs=new String[len];
for(int i=0;i<len;i++){
strs[i]=String.valueOf(nums[i]);
}
Arrays.sort(strs,(s1,s2)->(s2+s1).compareTo(s1+s2));

if(strs[0].charAt(0)=='0') return "0";

StringBuilder res=new StringBuilder();
for(String s:strs) res.append(s);
return res.toString();
}
}

<1…196197198…267>
ShunchiZhou

ShunchiZhou

267 posts
RSS
GitHub E-Mail Gitbook Linkedin
© 2024 ShunchiZhou
Powered by Hexo v5.4.0
|
0%