[LeetCode] Largest Number
2015-06-09 17:13
381 查看
Well, this problem is designed for radix sort. For more information about radix sort, Introduction to Algorithms, 3rd edition has some nice examples.
However, it can be solved simply by using the sort function while defining a new comparison function for it.
The code is pretty straight-forward.
However, it can be solved simply by using the sort function while defining a new comparison function for it.
The code is pretty straight-forward.
static bool cmp(int s, int t) { return to_string(s) + to_string(t) > to_string(t) + to_string(s); } string largestNumber(vector<int>& nums) { sort(nums.begin(), nums.end(), cmp); string ans; for (int i = 0; i < (int)nums.size(); i++) ans += to_string(nums[i]); if (ans[0] == '0') return "0"; return ans; }
相关文章推荐
- MySQL集群搭建步骤详解
- Unable to execute dex: Multiple dex files define 解决方法
- 【OGG】OGG的下载和安装篇
- Building,Packaging,Deploying,and Administering Applications and Types
- nodejs之socket.io模块
- java json字符串解析--遇到的问题
- AE影像处理时ISAVEAS不能实时写入文件
- Android Studio 获取数字签名的方法
- PHP生成图片太慢了。。有些都不出来、
- JAVA创建对象有哪几种方式
- SAT写作的真实面目
- 什么是预测
- RabbitHub开源情况及计划
- easyui-tabs 刷新当前tab页
- 属性选择器
- 这个地方沸腾,高手争雄,至尊大决战,从天上杀到地下,又从地上打到云霄上!
- poolboy的坑
- js内存泄露的几种情况详细探讨
- C++字符数组的赋值
- apache常用命令整理