leetcode_num179_Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
两两比較 能够利用sort函数来排序,自己定义compare函数。即比較规则
可用vector来取代数组。easy定位
bool compare(int a,int b){
string t1=to_string(a)+to_string(b);
string t2=to_string(b)+to_string(a);
return t1>t2;
}
//return to_string(a)+to_string(b)>to_string(b)+to_string(a);
class Solution {
public:
string largestNumber(vector<int> &num) {//use vector to present array
if(num.size()<=0)
return "";
sort(num.begin(),num.end(),compare);
string res;
for(int i=0;i<num.size();i++)
res+=to_string(num[i]);
return res[0]=='0'?"0":res;//only elements valued 0
}
};
leetcode_num179_Largest Number的更多相关文章
- JavaScript Math和Number对象
目录 1. Math 对象:数学对象,提供对数据的数学计算.如:获取绝对值.向上取整等.无构造函数,无法被初始化,只提供静态属性和方法. 2. Number 对象 :Js中提供数字的对象.包含整数.浮 ...
- Harmonic Number(调和级数+欧拉常数)
题意:求f(n)=1/1+1/2+1/3+1/4-1/n (1 ≤ n ≤ 108).,精确到10-8 (原题在文末) 知识点: 调和级数(即f(n))至今没有一个完全正确的公式, ...
- Java 特定规则排序-LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- 移除HTML5 input在type="number"时的上下小箭头
/*移除HTML5 input在type="number"时的上下小箭头*/ input::-webkit-outer-spin-button, input::-webkit-in ...
- iOS---The maximum number of apps for free development profiles has been reached.
真机调试免费App ID出现的问题The maximum number of apps for free development profiles has been reached.免费应用程序调试最 ...
- 有理数的稠密性(The rational points are dense on the number axis.)
每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis.
- [LeetCode] Minimum Number of Arrows to Burst Balloons 最少数量的箭引爆气球
There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...
- [LeetCode] Number of Boomerangs 回旋镖的数量
Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of po ...
随机推荐
- SiteMesh3使用实例和详解
一.SiteMesh介绍 SiteMesh是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的.[来自百度百科] 通俗的理解就是,SiteMesh把页面中变化的和 ...
- selenium3 + python - cookie定位
from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitimport time d ...
- git的常用命令。。
git的常用命令.. git help <command> 显示command的help git show 显示某次提交的内容 git show $id git co -- <f ...
- 运行Django项目指定IP和端口
默认IP和端口 python manage.py runserver 指定端口: python manage.py runserver 192.168.12.12:8080 此时会报错,我们需要修改配 ...
- ListView(2)最简单的上拉刷新、下拉刷新代码
效果 最简单的上拉刷新和下拉刷新,当listview滚动到底部时向上拉刷新数据.当listview滚动到最顶部时下拉刷新. 图1,上拉刷新 图2,下拉刷新 1.设置lisview 加载he ...
- Hibernate_01_初体验
hibernate开发的基本步骤: 编写配置文档hibernate.cfg.xml: 编写实体类: 生成对应实体类的映射文件并添加到配置文档中: 调用hibernate API进行测试. Hibern ...
- nodejs要远程连接另一个主机上的monogodb数据库服务器
我的mongodb是装在linux下的. 首先,先添加用户 1.首先在mongodb服务器主机上进行terminal命令行,输入 mongo 2.输入 use admin 进入用户管理数据库 3.db ...
- MySQL创建临时表
drop TEMPORARY table if EXISTS temp_table; create TEMPORARY table temp_table( id int not null, usern ...
- TensorFlow的序列模型代码解释(RNN、LSTM)---笔记(16)
1.学习单步的RNN:RNNCell.BasicRNNCell.BasicLSTMCell.LSTMCell.GRUCell (1)RNNCell 如果要学习TensorFlow中的RNN,第一站应该 ...
- eas之Uuid和BOSUuid 区别
BOSUuid 加入了BOSType的概念,这个唯一码跟 BOSType有关,里面包含了BOSType的信息. 根据BOSType可以生产BOSUuid,同样,根据BOSUuid也可以找到BOSTyp ...