当前位置:网站首页>Leetcode 179 Maximum number (2022.06.28)
Leetcode 179 Maximum number (2022.06.28)
2022-06-29 13:26:00 【ChaoYue_ miku】
Given a set of nonnegative integers nums, Rearrange the order of each number ( Each number cannot be split ) Make it the largest integer .
Be careful : The output can be very large , So you need to return a string instead of an integer .
Example 1:
Input :nums = [10,2]
Output :“210”
Example 2:
Input :nums = [3,30,34,5,9]
Output :“9534330”
Tips :
1 <= nums.length <= 100
0 <= nums[i] <= 109
source : Power button (LeetCode)
link :https://leetcode.cn/problems/largest-number
C++ Submission :
class Solution {
public:
string largestNumber(vector<int> &nums) {
sort(nums.begin(), nums.end(), [](const int &x, const int &y) {
long sx = 10, sy = 10;
while (sx <= x) {
sx *= 10;
}
while (sy <= y) {
sy *= 10;
}
return sy * x + y > sx * y + x;
});
if (nums[0] == 0) {
return "0";
}
string ret;
for (int &x : nums) {
ret += to_string(x);
}
return ret;
}
};
边栏推荐
- C#实现顺序表定义、插入、删除、查找操作
- Yolo series combs (IX) first taste of newly baked yolov6
- 【云驻共创】工业智慧“大脑”,老厂焕新的加速秘籍
- AcWing 234 放弃测试
- Install the terrain ovirt plug-in to provide automated management for ovirt
- C#实现队列结构定义、入队、出队操作
- asp. Net project using aspnet_ compiler. Exe Publishing
- CVPR2022 | 弱监督多标签分类中的损失问题
- 项目管理复习题
- Detailed explanation on configuration and commissioning of third-party servo of Beifu TwinCAT -- Taking Huichuan is620n as an example
猜你喜欢

leetcode 第 299场周赛

UI file introduction in QT

C语言字符函数

【无标题】安装依赖报错:Refusing to install package with name “***“ under a package

CVPR2022 | 弱监督多标签分类中的损失问题

CVPR2022 | 可精简域适应

C language memory function

Cvpr2022 𞓜 future transformer with long-term action expectation

Cvpr2022 | a convnet for the 2020s & how to design neural network Summary

iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务
随机推荐
AcWing 234 放弃测试
The role of each part of Neural Network & thoroughly understand neural network
Force buckle: merging two ordered linked lists
bind原理及模拟实现
Cvpr2022 𞓜 loss problem in weakly supervised multi label classification
netdata邮件告警配置
async原理实现
C语言字符函数
PyGame flips the image
Cvpr2022 | knowledge distillation through target aware transformer
Yolo series combs (IX) first taste of newly baked yolov6
别再重复造轮子了,推荐使用 Google Guava 开源工具类库,真心强大!
Principle and Simulation of bind
Gee - American landfire fire fire data set
服务器上的RTC时间与世界时间不一致解决办法
Code tidiness learning notes
Definition of C # clue binary tree
强大、优秀的文件管理软件评测:图片管理、书籍管理、文献管理
AOSP ~ logcat persistence
B+ tree | MySQL index usage principle