# LeetCode 179. Largest Number

154 篇文章 0 订阅
8 篇文章 0 订阅

### 题目要求

Given a list of non negative integers, arrange them such that they form the largest number.

For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.

Note: The result may be very large, so you need to return a string instead of an integer.

### 解法分析

java中有一个接口为Comparable，如下。

public interface Comparable<T> {
/**
* Compares this object with the specified object for order.  Returns a
* negative integer, zero, or a positive integer as this object is less
* than, equal to, or greater than the specified object.
* ...
*/
public int compareTo(T o);

### 解题代码

    public String largestNumber(int[] nums) {
for (int num : nums) {
if (num == 0) {
continue;
}
}
.size()];
StringBuilder sb = new StringBuilder();
for (int i = integerShadows2.length - 1; i >= 0; i--) {
}
if (sb.toString().matches("0+")) {
return "0";
} else {
return sb.toString();
}
}

public int ori;
public String oriStr;

public IntegerShadow(int o, String s) {
this.ori = o;
this.oriStr = s;
}

@Override
return (this.oriStr + o.oriStr).compareTo(o.oriStr + this.oriStr);
}
}
• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
03-11 427
01-18 7556
11-11 1810
11-21 1355
11-17 1185
12-24 655
11-01 409
11-01 317
12-04 150
12-08 149
12-08 190
12-02 191

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

_海阔天空

¥1 ¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。