leetcode 179 最大数
LeetCode 最大数
2023-09-27 14:29:24 时间
最大数
高刷题
class Solution {
public:
static bool cmp( string &s1 , string &s2 )
{
string tmp1 , tmp2;
tmp1 = s1 + s2;
tmp2 = s2 + s1;
return tmp1 > tmp2;
}
string largestNumber(vector<int>& nums) {
vector<string> tmpStr;
string result;
for(int i=0 ; i<nums.size() ; i++)
{
string tmp = to_string(nums[i]);
tmpStr.push_back(tmp);
}
sort(tmpStr.begin() , tmpStr.end() , cmp);
for(int i=0 ; i<tmpStr.size() ; i++)
{
result += tmpStr[i];
}
if(result[0] == '0') return "0";
return result;
}
};
相关文章
- Leetcode: Third Maximum Number
- Leetcode: Factorial Trailing Zeroes
- LeetCode 67 Add Binary(二进制相加)(*)
- Leetcode刷题记录:构建最大数二叉树
- leetcode 179. 最大数 解题报告
- LeetCode高频题46. 全排列
- 后缀数组的应用:[Leetcode] 321.拼接最大数(困难)
- JS Leetcode 74. 搜索二维矩阵题解分析,二分法与坐标轴法
- 110、【树与二叉树】leetcode ——450. 删除二叉搜索树中的节点:递归法+迭代法(C++版本)
- 【LeetCode】18. 4Sum (2 solutions)
- [LeetCode OJ] Copy List with Random Pointer 扩大
- [LeetCode] Bricks Falling When Hit 碰撞时砖头掉落
- [LeetCode] 731. My Calendar II 我的日历之二