solution.md 1.7 KB
Newer Older
ToTensor's avatar
ToTensor 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
# 最大数

<p>给定一组非负整数 <code>nums</code>,重新排列每个数的顺序(每个数不可拆分)使之组成一个最大的整数。</p>

<p><strong>注意:</strong>输出结果可能非常大,所以你需要返回一个字符串而不是整数。</p>

<p> </p>

<p><strong>示例 1:</strong></p>

<pre>
<strong>输入<code></code></strong><code>nums = [10,2]</code>
<strong>输出:</strong><code>"210"</code></pre>

<p><strong>示例 2:</strong></p>

<pre>
<strong>输入<code></code></strong><code>nums = [3,30,34,5,9]</code>
<strong>输出:</strong><code>"9534330"</code>
</pre>

<p><strong>示例 3:</strong></p>

<pre>
<strong>输入<code></code></strong>nums = [1]
<strong>输出:</strong>"1"
</pre>

<p><strong>示例 4:</strong></p>

<pre>
<strong>输入<code></code></strong>nums = [10]
<strong>输出:</strong>"10"
</pre>

<p> </p>

<p><strong>提示:</strong></p>

<ul>
	<li><code>1 <= nums.length <= 100</code></li>
	<li><code>0 <= nums[i] <= 10<sup>9</sup></code></li>
</ul>


## template

```python

ToTensor's avatar
ToTensor 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
class Solution(object):
    def largestNumber(self, nums):
        n = len(nums)

        for i in range(n):
            for j in range(n - i - 1):
                temp_1 = str(nums[j])
                temp_2 = str(nums[j + 1])
                if int(temp_1 + temp_2) < int(temp_2 + temp_1):
                    temp = nums[j]
                    nums[j] = nums[j + 1]
                    nums[j + 1] = temp
        output = ""
        for num in nums:
            output = output + str(num)
        return str(int(output))
ToTensor's avatar
ToTensor 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

```

## 答案

```python

```

## 选项

### A

```python

```

### B

```python

```

### C

```python

```