[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 ...
随机推荐
- 【Struts2学习笔记(11)】对action的输入校验和XML配置方式实现对action的全部方法进行输入校验
在struts2中,我们能够实现对action的全部方法进行校验或者对action的指定方法进行校验. 对于输入校验struts2提供了两种实现方法: 1. 採用手工编写代码实现. 2. 基于XML配 ...
- g++编C++11/C++0x遇到的问题
在看<Cplusplus Concurrency In Action Practical Multithreading>当遇到第一个样品: #include<iostream> ...
- LVS的调度算法分析
LVS调度算法 一.静态调度算法 1. rr(round robin)轮询调度,即调度器将客户端的请求依次的传递给内部的服务器,从1到N,算法简洁,无须记录状态,但是不考虑每台服务器的性能. 配置如 ...
- python+ueditor+七牛云存储整合
开发环境:python pyramid. 參考网址:http://developer.qiniu.com/docs/v6/sdk/python-sdk.html,http://my.oschina.n ...
- linux zombie process相关学习
1. zombie process是什么? zombie process是那些在系统中已经死掉的process, 通过ps -A | grep defunct可以查看系统中有多少zombie proc ...
- 【C#遗补】获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPath的区别
原文:[C#遗补]获取应用程序路径之System.IO.Directory.GetCurrentDirectory和System.Windows.Forms.Application.StartupPa ...
- CC ANUMLA(STL的运用)
题目连接:http://www.codechef.com/problems/ANUMLA 题意:给一个序列所有子集和(2^n个子集),复原这个序列... 如:0 1 1 2 2 3 3 4 原序列为1 ...
- R12 付款过程请求-功能和技术信息 (文档 ID 1537521.1)
In this Document Abstract History Details _afrLoop=2234450430619177&id=1537521.1&dis ...
- Cordova CLI源码分析(三)——初始化
本部分主要涉及以下三个文件 1 cli.js 2 cordova.js 3 events.js 通过前一篇package.json的分析,可以知道,当命令行执行cordova相关命令时,首先调用mai ...
- sql server 常用语法
--1 创建数据库 DROP DATABASE mydb1 CREATE DATABASE mydb1 ON ( NAME ='mydb1',FILENAME='D:\mydb1.mdf') LOG ...