当前位置:网站首页>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;
}
};
边栏推荐
- ArcGIS中对面状河流进行等距分段【渐变赋色、污染物扩散】
- Interesting talk on network protocol (II) transport layer
- 项目管理复习题
- The role of each part of Neural Network & thoroughly understand neural network
- asp. Net project using aspnet_ compiler. Exe Publishing
- Design of commodity search engine recommendation system
- Code tidiness learning notes
- Application Service Vulnerability scanning and exploitation of network security skills competition in secondary vocational schools (SSH private key disclosure)
- Schiederwerk Power Supply repair smps12 / 50 pfc3800 Analysis
- Getting started with mybaits (including example tutorial and source code)
猜你喜欢

C language character function

Schiederwerk Power Supply repair smps12 / 50 pfc3800 Analysis

CVPR2022 | 可精简域适应

Another "provincial capital university", coming!

matplotlib的imshow函数显示灰度图像要设置vmin和vmax2个参数

iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file

C#二叉树结构定义、添加节点值

Cvpr2022 𞓜 thin domain adaptation

Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!
随机推荐
三维模型下载与动画控制
mysql调优
STK_ Gltf model
If I am in Shenzhen, where can I open an account? In addition, is it safe to open an account online now?
Install the terrain ovirt plug-in to provide automated management for ovirt
C语言内存函数
CVPR2022 | A ConvNet for the 2020s & 如何设计神经网络总结
Tutorial on building pytoch model from zero (V) writing training process -- some basic configurations
Cvpr2022 | a convnet for the 2020s & how to design neural network Summary
C language memory function
PG基础篇--逻辑结构管理(1)
Rslo: self supervised lidar odometer (real time + high precision, icra2022)
Yolo series combs (IX) first taste of newly baked yolov6
Acwing game 57
iMile 利用 Zadig 多云环境周部署千次,跨云跨地域持续交付全球业务
Shell judges whether the command is executed successfully
别再重复造轮子了,推荐使用 Google Guava 开源工具类库,真心强大!
Can I open an account online? Is it safe
Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!
Cvpr2022 | knowledge distillation through target aware transformer