# LeetCode 179. Largest Number

162人阅读 评论(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

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：99281次
• 积分：2705
• 等级：
• 排名：第13821名
• 原创：178篇
• 转载：21篇
• 译文：0篇
• 评论：9条
文章分类
阅读排行
评论排行
最新评论