Leetcode179. Largest Number最大数
给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数。
示例 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最大数的更多相关文章
- LeetCode-179. Largest Number
179. Largest Number Given a list of non negative integers, arrange them such that they form the larg ...
- [LeetCode179]Largest Number
题目: Given a list of non negative integers, arrange them such that they form the largest number. For ...
- [leetcode]179. Largest Number最大数
Given a list of non negative integers, arrange them such that they form the largest number. Input: [ ...
- [Swift]LeetCode179. 最大数 | Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. Example ...
- LeetCode 179. 最大数(Largest Number) 21
179. 最大数 179. Largest Number 题目描述 给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 每日一算法2019/5/24Day 21LeetCode179. La ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- [LeetCode] Largest Number 最大组合数
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- 【leetcode】Largest Number
题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...
- leetcode 179. Largest Number 求最大组合数 ---------- java
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
随机推荐
- 靖烜小哥哥之mybatis总结
MyBatis是一个半自动映射的框架.“半自动”是相对于Hibernate全表映射而言的,MyBatis需要手动匹配提供POJO.SQL和映射关系,而Hibernate只需提供POJO和映射关系即可. ...
- <爬虫>黑板爬虫闯关01
import requests from lxml import etree import time ''' 黑板爬虫闯关 网址:http://www.heibanke.com/lesson/craw ...
- JAVA中日期 yyyy-MM-dd HH:mm:ss和yyyy-MM-dd hh:mm:ss的区别
HH是24小时制,hh是12小时制 区别就是:大写的H是二十四小时制的小时数(0-23),小写的h是十二小时制的小时数(am/pm 1-12) //24小时制 SimpleDateFormat sdf ...
- .Global.asax.cs中的方法的含义
Application_Init:在每一个HttpApplication实例初始化的时候执行 Application_Disposed:在每一个HttpApplication实例被销毁之前执行 App ...
- 帝国cms学习
手册地址1 手册地址2 入门 安装: 将下载的upload里的文件上传到网站更目录 然后 域名/e/install/index.php Warning: Use of undefined consta ...
- commons lang3的StringUtils中isEmpty()方法和isBlank()方法的区别
先给结论: 1. StringUtils.isEmpty()中的空格作非空处理2. StringUtils.isNotEmpty()是StringUtils.isEmpty()取反后的结果3. Str ...
- 转载:shell中#*,##*,#*,##*,% *,%% *的含义及用法
介绍下Shell中的${}.##和%%使用范例,本文给出了不同情况下得到的结果.假设定义了一个变量为:代码如下:file=/dir1/dir2/dir3/my.file.txt可以用${ }分别替换得 ...
- vertx使用过程中浏览器端Cookie重复问题
[问题描述] 背景: 使用vertx提供的服务,使用Dispatcher做路由转发,内部通过routingcontext做请求传递及响应. 现象: 在谷歌浏览器的Network中,看到Cookie中有 ...
- 爆表!猜猜这个大会的IQ总值有多高?
“人人可及的未来,同样存在于「日拱一卒」的琐碎生活当中,那也是技术对生活最为直观的改变和演进.” “以通神明之德,以类万物之情”,这句来自<易经>的话,放到现今也合宜. 人类掌控事物发展的 ...
- HTML值改变事件
1.动态拼接html[表格中,如bootstrap grid] return '<input type="text" name="bjce" onchan ...