给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数。

示例 1:

输入: [10,2] 输出: 210

示例 2:

输入: [3,30,34,5,9] 输出: 9534330

说明: 输出结果可能非常大,所以你需要返回一个字符串而不是整数。

注意全是0的情况

bool cmp3(int x, int y)
{
string str1 = to_string(x);
string str2 = to_string(y); return (str1 + str2) > (str2 + str1);
} class Solution {
public:
string largestNumber(vector<int>& nums)
{
if(nums.size() == 0)
return "0";
sort(nums.begin(), nums.end(), cmp3);
string str = "";
int x = 0;
for(int i = 0; i < nums.size(); i++)
{
x += nums[i];
str = str + to_string(nums[i]);
}
if(x == 0)
return "0";
return str;
}
};

Leetcode179. Largest Number最大数的更多相关文章

  1. LeetCode-179. Largest Number

    179. Largest Number Given a list of non negative integers, arrange them such that they form the larg ...

  2. [LeetCode179]Largest Number

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

  3. [leetcode]179. Largest Number最大数

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

  4. [Swift]LeetCode179. 最大数 | Largest Number

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

  5. LeetCode 179. 最大数(Largest Number) 21

    179. 最大数 179. Largest Number 题目描述 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 每日一算法2019/5/24Day 21LeetCode179. La ...

  6. Java 特定规则排序-LeetCode 179 Largest Number

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

  7. [LeetCode] Largest Number 最大组合数

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

  8. 【leetcode】Largest Number

    题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...

  9. leetcode 179. Largest Number 求最大组合数 ---------- java

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

随机推荐

  1. 面试系列 30 如何自己设计一个类似dubbo的rpc框架

    其实一般问到你这问题,你起码不能认怂,因为既然咱们这个课程是短期的面试突击训练课程,那我不可能给你深入讲解什么kafka源码剖析,dubbo源码剖析,何况我就算讲了,你要真的消化理解和吸收,起码个把月 ...

  2. 【数位DP】[LOJ10168] 恨7不成妻

    还是数位DP... 状态:$f[x][val][sum]$表示当前第x位,当前数字为val,当前各位数字和为sum 观察到$val$,$sum$过大,很套路地模7即可... 每个状态存储三个要用到的值 ...

  3. reg命令详解

    reg命令是Windows提供的,它可以添加.更改和显示注册表项中的注册表子项信息和值. 1,reg add 将新的子项或项添加到注册表中  语法:reg add KeyName [/v EntryN ...

  4. 进程监控驱动 PsSetCreateProcessNotifyRoutine

    函数原型: NTSTATUS PsSetCreateProcessNotifyRoutine( _In_ PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine, _ ...

  5. table方法也属于模型类的连贯操作方法之一

    table方法也属于模型类的连贯操作方法之一,主要用于指定操作的数据表. 用法 一般情况下,操作模型的时候系统能够自动识别当前对应的数据表,所以,使用table方法的情况通常是为了: 切换操作的数据表 ...

  6. LUOGU P1342 请柬(最短路)

    传送门 解题思路 又是一道语文题,弄清楚题意之后其实就能想出来了,从1跑一遍最短路,把$dis[n]$加入答案.在建个反图跑一遍最短路,把$dis[n]_$加入最短路就行了.第一遍是去的时候,第二遍是 ...

  7. vuex结合vue-cookies的使用

    一.创建vuex import Vue from 'vue' import Vuex from 'vuex' import cookie from "vue-cookies" Vu ...

  8. 莫烦PyTorch学习笔记(六)——批处理

    1.要点 Torch 中提供了一种帮你整理你的数据结构的好东西, 叫做 DataLoader, 我们能用它来包装自己的数据, 进行批训练. 而且批训练可以有很多种途径. 2.DataLoader Da ...

  9. System.Web.Mvc.ModelValidationResult.cs

    ylbtech-System.Web.Mvc.ModelValidationResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutr ...

  10. Spring注解驱动(上)

    记录常用的spring注解 1.@Configuration 和 @Bean spring中可以使用xml 的方式进行配置, 也可以使用 @ Configuration 来指定一个类为配置类, 并使用 ...