[LeetCode179]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
.
Note: The result may be very large, so you need to return a string instead of an integer.
思路:将数字按照最高位的大小排序,然后连接成字符串即可
代码:
public class Solution {
public string LargestNumber(int[] nums) {
Array.Sort(nums,CompareByTopDigit);
if(nums[nums.Length-] == ) return "";
string s = "";
for(int i = nums.Length - ; i >= ; i--)
{
s += nums[i].ToString();
}
return s;
} public int CompareByTopDigit(int a, int b)
{
return (a + "" + b).CompareTo(b + "" + a);
}
}
[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最大数
给定一组非负整数,重新排列它们的顺序使之组成一个最大的整数. 示例 1: 输入: [10,2] 输出: 210 示例 2: 输入: [3,30,34,5,9] 输出: 9534330 说明: 输出结果 ...
- [Swift]LeetCode179. 最大数 | Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. Example ...
- 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 ...
- JavaScript中sort方法的一个坑(leetcode 179. Largest Number)
在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...
- 【leetcode】Largest Number ★
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
随机推荐
- 201215-03-19---cocos2dx内存管理--具体解释
因为cocos2dx我们的使用c++写的,所以内存管理就是一个绕只是去的坎,这个你不懂内存仅仅懂业务逻辑的话,还玩什么c++,今天看了半天这个东西,事实上本质上是理解的,可是就是有一个过不去的坎,最终 ...
- graphterm 0.40.1 : Python Package Index
graphterm 0.40.1 : Python Package Index graphterm 0.40.1 Downloads ↓ A Graphical Terminal Interface ...
- Fast portable non-blocking network programming with Libevent
Fast portable non-blocking network programming with Libevent Fast portable non-blocking network prog ...
- SE 2014年4月12日
BGP基础实验 拓扑 步骤: 1. 完成基本的配置 2. 按照需求自治系统AS 100 全网运行OSPF 单区域 3. 完成BGP基本配置 [RT2]bgp 100 [RT2-bgp]peer 67. ...
- 从头来之【图解针对虚拟机iOS开发环境搭建】 (转)
1.下载Mac OSX10.9. 点击下载 2.下载VMware Workstation 10,点击下载,网页中包含序列号.安装VM. 3.VM10-MacOS补丁.用于创建苹果虚拟机. 安装VM就不 ...
- poj3667(线段树)
题目连接:http://poj.org/problem?id=3667 题意:1 a:询问是不是有连续长度为a的空房间,有的话住进最左边 2 a b:将[a,a+b-1]的房间清空 线段树操作:upd ...
- 使用Nexus搭建企业maven仓库(二)
先阅读<使用Nexus搭建企业maven仓库(一)> http://blog.csdn.net/ouyida3/article/details/40747545 1.官网眼下最新的版本号是 ...
- bash,bg,bind,break,builtin,caller,compgen, complete,compopt,continue,declare,dirs,disown,enable,eval,exec,expo
bash,bg,bind,break,builtin,caller,compgen, complete,compopt,continue,declare,dirs,disown,enable,eval ...
- windows使用nginx+memcached实现负载均衡和session或者缓存共享
windows使用nginx+memcached实现负载均衡和session或者缓存共享 两台server server1:115.29.186.215 windows2008 64位操作系统 ser ...
- vim ---- 自己主动的按钮indent该命令
当使用vim一段代码的副本到一个程序时,有,经常indent会有一些问题. . 下面的这个强大的命令,使您可以一键码具有很好的格式. gg=G 样品: