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

小技巧为排序中的比较函数,另外记住不能有=号

class Solution {
public:
static bool compareFunc(string &s1, string& s2) {
return s1+s2 > s2+s1;
}
string largestNumber(vector<int>& nums) {
string res;
int n = nums.size();
vector<string> vecStr;
for (int i = ; i < n; i++) {
vecStr.push_back(to_string(nums[i]));
}
sort(vecStr.begin(), vecStr.end(), compareFunc);
if(vecStr[] == "") return ""; for (int i = ; i < n; i++) {
res += vecStr[i];
}
return res;
}
};

Largest Number的更多相关文章

  1. Java 特定规则排序-LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  2. [LeetCode] Largest Number 最大组合数

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  3. 【leetcode】Largest Number

    题目简述: Given a list of non negative integers, arrange them such that they form the largest number. Fo ...

  4. leetcode 179. Largest Number 求最大组合数 ---------- java

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  5. LeetCode-179. Largest Number

    179. Largest Number Given a list of non negative integers, arrange them such that they form the larg ...

  6. JavaScript中sort方法的一个坑(leetcode 179. Largest Number)

    在做 Largest Number 这道题之前,我对 sort 方法的用法是非常自信的.我很清楚不传比较因子的排序会根据元素字典序(字符串的UNICODE码位点)来排,如果要根据大小排序,需要传入一个 ...

  7. 【leetcode】Largest Number ★

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  8. Java for LeetCode 179 Largest Number

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

  9. 179. Largest Number -- 数字字符串比较大小

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...

随机推荐

  1. [问题2014S07] 复旦高等代数II(13级)每周一题(第七教学周)

    [问题2014S07]  设 \(A\in M_n(\mathbb{K})\) 在数域 \(\mathbb{K}\) 上的初等因子组为 \(P_1(\lambda)^{e_1},P_2(\lambda ...

  2. BZOJ 2600: [Ioi2011]ricehub

    2600: [Ioi2011]ricehub Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 628  Solved: 325[Submit][Stat ...

  3. [Mysql] mysql临时表corrupt

    问题描述 机房临时硬件问题, 机器掉电. 恢复后, 重启mysql进程, 结果出现core dump. 而且一直循环, 无法终止, 只能kill掉. backtrace如下. # service my ...

  4. static(静态、修饰符)

    static(静态.修饰符) static修饰成员变量时:static修饰成员变量时,那么该成员变量的数据就是一个共享的数据. 静态成员变量的访问方式: 方式一: 使用对象进行访问. 对象.属性名 方 ...

  5. Keycode对照表

    字母和数字键的键码值(keyCode) 按键 键码 按键 键码 按键 键码 按键 键码 A 65 J 74 S 83 1 49 B 66 K 75 T 84 2 50 C 67 L 76 U 85 3 ...

  6. Head First 设计模式 --5 单例模式

    单例模式:确保一个类只有一个实例,并提供一个全局访问点.用到的设计原则:1.封装变化2.组合优于集成3.针对接口变成而不是针对实现4.为交互对象之间的松耦合设计而努力5.类应该对扩展开放,对修改关闭6 ...

  7. Skyfree的毕业论文 《系统封装与部署的深入研究》

    Skyfree的毕业论文 <系统封装与部署的深入研究> https://www.itsk.com/thread-197-1-4.html Skyfree 发表于 2007-9-13 07: ...

  8. VIM 代码折叠

    VIM 代码折叠 VIM代码折叠方式可以用"foldmethod"选项来设置,如: set foldmethod=indent 有6种方式来折叠代码 1. manual //手工定 ...

  9. .NET日常总结

    属性: AccepButton:按钮在按回车键时执行(确定). CancleButton:按钮在按ESC时执行(取消). MinimizeBox:用于设置窗体上是否会出现最小化按钮. Maximize ...

  10. yii2-basic后台管理功能开发之一:引入模板

    前景:哎没想到用php的yii2框架写了官网……自己选择的框架,跪着也要码完,当年用yii2-basic搭建了官网,原是想偷懒的,没想到还要写后台.... 需求:实现一个可编辑页面图片及新闻内容的后台 ...