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 ...
随机推荐
- websocket 实现消息推送(转)
介绍 现很多网站为了实现即时通讯,所用的技术都是轮询(polling).轮询是在特定的的时间间隔(如每1秒),由浏览器对服务器发出HTTP request,然后由服务器返回最新的数据给客服端的浏览器. ...
- linux流量监控iftop命令安装详解
iftop跟nload差不多,也是捕获网卡流量的命令,nload的安装见之前发布的教程:http://www.cnblogs.com/catlee/p/5703541.html 开始安装.本文以cen ...
- Linux安装Java与Eclipse
Linux安装Java和Eclipse 一.准备工作 1.下载jdk https://www.oracle.com/technetwork/java/javase/downloads/jdk8-do ...
- Android开发 TextView的开发记录
前言 此篇博客是记录一些TextView开发上一些少用的开发功能项.目前开发记录如下: 添加图片 文字滚动 添加省略号 实现长文的收起和展开功能 改变一个字符串里自定字符的颜色或者大小 效果字体(粗体 ...
- falcon监控指标
mysql监控指标: 流量状态: Bytes_received/s #平均每秒从所有客户端接收到的字节数,单位KB Bytes_sent/s #平均每秒发送给所有客户端的字节数,单位KB
- configparser 配置文件模块
#_author:star#date:2019/11/7# configparser 配置文件模块import configparserconfig=configparser.ConfigParser ...
- 2-sat——poj3678经典建图
比较经典的建图,详见进阶指南 2-sat一般要用到tarjan来求强连通分量 /*2-sat要加的是具有强制关系的边*/ #include<iostream> #include<cs ...
- raft学习
http://thesecretlivesofdata.com/raft/ 选举 角色: leader 领导者 Follower跟随者 Candidate候选者 如果跟随者在一定时间内,么有收到领 ...
- ubuntu挂载和挂载NTFS分区命令
1.挂载 首先安装NTFS-3g,不过Ubuntu一般自带: sudo apt install ntfs-3g 查看分区信息: sudo fdisk -l 结果类似: /dev/sda1 * ...
- hibernate 映射总结
单向一对多实体配置:在一的实体中设置多的一方SET集合配置文件:在一的一方用set 设置 one to many表配置:多方表的外键指向一方表的主键; 双向一对多实体配置:在一的实体中设置多的一方SE ...