[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 ...
随机推荐
- android Vibrator 用法
private Vibrator mvibrator; 1.服务的句柄 mvibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); 或者 ...
- 008实现一个算法从一个单链表中返回倒数第n个元素(keep it up)
我们维护两个指针, 它们之间的距离为n. 然后.我将这两个指针同步地在这个单链表上移动,保持它们的距离 为n不变. 那么, 当第二个指针指到空时.第一个指针即为所求. #include <ios ...
- HTML5线性图表 图表数据区域可着色
这是一款基于Canvas的HTML5图表应用,在图表数据初始化的时候伴随动画效果. 在线演示: 点击演示 源代码下载: 点击下载 核心jQuery代码: var myData = { labels ...
- mysql增量ID
启动值更改方法
在mysql很多朋友感到场AUTO_INCREMENT增量型ID值它不能被改变,其实这种认识是错误的,这里mysql增量ID开始值更改和设置. 设置自动递增字段的通常的方法: 格时加入: create ...
- HTML5: Screen Orientation API
媒体的询问取决于智能手机和平板布局调整的方向一致网站.但有时候你被锁定在一个希腊网站特定方向.横向或纵向.此时,是本机格式可以指定保健应用. APP只显示在一个预设格式-独立于实际设备方向.通过使用H ...
- Storm-0.9.2-incubating源代码编译打包
近期遇到一些同学询问Storm-0.9.2-incubating源代码编译打包的问题,现将编译步骤说明例如以下: 1.凝视掉project各pom文件里关于maven插件(maven-gpg-plug ...
- ORA-00600: 内部错误代码, 参数: [kqlnrc_1]
如以下的错误: Mon Mar 31 18:45:59 2014 Errors in file /oracle/app/oracle/diag/rdbms/zscims/zscims2/trace/z ...
- 控制台打印Hibernate的SQL语句显示绑定参数值
问题? 使用Hibernate提供的show_sql内置属性true只能输出类似于下面的SQL语句:Hibernate: insert into user(name,password) value ...
- DIV 居中对齐
<div style="text-align:center;margin-right:auto;margin-left:auto">
- ecshop网站建设手机版wap版出现lib.debug.php on line 303
首先我们可以看到页面中提示\includes\lib.debug.php on line 303这样的错误,那么我们首先应该找到这个文件的低303行.代码是: $pa = &new Print ...