题目:

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);
}
}

最新文章

  1. 配置react native遇到的问题
  2. 搭建自己的apache tomcat php mysql 环境和WordPress站点制作
  3. mysql5.7碰到的坑
  4. linux下google chrome浏览器字体修改
  5. codevs 2851 菜菜买气球
  6. 【Android】应用程序启动过程源码分析
  7. js伪数组及转换
  8. PLSQL_Oracle簇表和簇表管理Index clustered tables(案例)
  9. nova service-list
  10. PHP操作MongoDB数据库
  11. win下Java环境安装
  12. bzoj1901:Zju2112 Dynamic Rankings
  13. Asp.Net--回调技术
  14. Access restriction: The type * is not accessible due to restrict,报错问题
  15. jquery prop()方法 解决全选 不全选 反选 问题 解决执行一次不不能再执行问题
  16. Codeforces Round #243 (Div. 1)-A,B,C-D
  17. 看完这篇文章才对【GIT】有了大彻大悟的认识
  18. mouseleave 和 mouseout 区别
  19. 转载]浅析DEDECMS织梦留言板调用网站head.htm以及自定义的方法
  20. css区分ie8/ie9/ie10/ie11 chrome firefox的代码

热门文章

  1. SpringMVC配置+小例子
  2. Wix学习整理(6)——安装快捷方式
  3. Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space 解决!
  4. Androidclient和server端数据交互的第一种方法
  5. linux下用shell删除三天前或者三天内的文件
  6. libgdx如何调用android平台内容
  7. 教你怎么去一个APP的JSON数据,你懂的
  8. android app崩溃日志收集以及上传
  9. 建立qemu桥接的网络连接
  10. codeforces293E (树上点分治+树状数组)