当前位置:网站首页>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;
}
};
边栏推荐
- Design of commodity search engine recommendation system
- How to count project codes (e.g. wechat applets)
- Proteus simulation of buck switching power supply based on 51 single chip microcomputer
- 运动App如何实现端侧后台保活,让运动记录更完整?
- @Table burst red
- Equidistant segmentation of surface rivers in ArcGIS [gradient coloring, pollutant diffusion]
- 服务器上的RTC时间与世界时间不一致解决办法
- If I am in Shenzhen, where can I open an account? In addition, is it safe to open an account online now?
- Pod security policy (PSP)
- C language memory function
猜你喜欢

趣谈网络协议(二)传输层

YOLO系列梳理(九)初尝新鲜出炉的YOLOv6

CVPR2022 | A ConvNet for the 2020s & 如何设计神经网络总结

揭秘!付费会员制下的那些小心机!

Cnpm reports an error 'cnpm' is not an internal or external command, nor is it a runnable program or batch file

Cvpr2022 𞓜 future transformer with long-term action expectation

UI file introduction in QT

使用 Gerrit + Zadig 实现主干开发主干发布(含字节飞书实践)

安装typescript环境并开启VSCode自动监视编译ts文件为js文件

【无标题】安装依赖报错:Refusing to install package with name “***“ under a package
随机推荐
iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务
Cnpm reports an error 'cnpm' is not an internal or external command, nor is it a runnable program or batch file
Cvpr2022 | reexamine pooling: your receptive field is not the best
服务器上的RTC时间与世界时间不一致解决办法
C#线索二叉树的定义
自主可控再下一城!首套国产ARTIQ架构量子计算测控系统发布
AOSP ~ logcat persistence
C # implementation of binary tree non recursive middle order traversal program
*打卡算法*LeetCode 146. LRU 缓存 算法解析
STK_ Gltf model
Write a shell script to find the "reverse order" of a number“
Shell judges whether the command is executed successfully
Hystrix circuit breaker
If I am in Shenzhen, where can I open an account? In addition, is it safe to open an account online now?
C language simulation to realize all character functions
Cvpr2022 𞓜 thin domain adaptation
【无标题】安装依赖报错:Refusing to install package with name “***“ under a package
使用 Gerrit + Zadig 实现主干开发主干发布(含字节飞书实践)
360数科新能源专项产品规模突破60亿
技术分享| 融合调度中的广播功能设计