###### Algorithms—179.Largest Number

public class Solution {
public String largestNumber(int[] nums) {
if (nums.length == 1) {
return String.valueOf(nums[0]);
}
int temp = 0;
for (int i = nums.length - 1; i > 0; i--) {
for (int j = 0; j < i; ++j) {
if (new Solution().compare(nums[j], nums[j + 1])) {
temp = nums[j];
nums[j] = nums[j + 1];
nums[j + 1] = temp;
}
}
}
StringBuffer sb = new StringBuffer();
if (nums[nums.length - 1] == 0) {
return "0";
}
for (int i = nums.length - 1; i >= 0; i--) {
sb.append(String.valueOf(nums[i]));
}
return sb.toString();
}

public boolean compare(int a, int b) {
char[] ca=(String.valueOf(a)+String.valueOf(b)).toCharArray();
char[] cb=(String.valueOf(b)+String.valueOf(a)).toCharArray();
for (int i = 0; i < ca.length; i++) {
if (ca[i]>cb[i]) {
return true;
}
if (ca[i]<cb[i]) {
return false;
}
}
return false;
}
}

#### 179.Largest Number

2015-07-01 08:57:29

#### [LeetCode]179.Largest Number

2015-01-18 13:55:44

#### [leetcode] 179.Largest Number

2015-07-16 17:48:56

#### A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS(试译)

2016-04-03 09:41:15

#### princeton algorithms part 1 第一周作业题

2018-01-03 02:01:28

#### leetcode179-Largest Number(把数组排成最大的数)

2016-06-11 11:52:22

#### Algorithms—202.Happy Number

2015-06-21 22:58:40

#### Algorithms—9.Palindrome Number

2015-07-07 11:28:08

#### Algorithms—287.Find the Duplicate Number

2015-10-08 15:20:48

#### Algorithms—264.Ugly Number II

2015-08-24 15:24:29

## 不良信息举报

Algorithms—179.Largest Number