当前位置:网站首页>Sword finger offer note: t45. arrange the array into the smallest number
Sword finger offer note: t45. arrange the array into the smallest number
2022-07-27 11:48:00 【Ignorant little nine】
T45. Make the array the smallest number
Enter an array of nonnegative integers , Put all the numbers in the array together to form a number , Print the smallest of all the numbers that can be spliced .
Example 1:
Input : [10,2]
Output : “102”
Example 2:
Input : [3,30,34,5,9]
Output : “3033459”
Tips :
0 < nums.length <= 100
explain :
The output can be very large , So you need to return a string instead of an integer
The stitched numbers may have a lead 0, The final result does not need to remove the lead 0
solution 1
Didn't do it
solution 2
class Solution {
public String minNumber(int[] nums) {
List<String> strList = new ArrayList<>();
for (int num : nums) {
strList.add(String.valueOf(num));
}
strList.sort((a, b) -> (a + b).compareTo(b + a));
StringBuilder sb = new StringBuilder();
for (String str : strList) {
sb.append(str);
}
return sb.toString();
}
}
author : Painter Dapeng
link :https://leetcode-cn.com/leetbook/read/illustrate-lcof/o585xr/
source : Power button (LeetCode)
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .
边栏推荐
- pytorch和tensorflow一样展示summary
- LeetCode 03: T58. 最后一个单词的长度(简单); 剑指 Offer 05. 替换空格(简单); 剑指 Offer 58 - II. 左旋转字符串(简单)
- Shell编程之正则表达式(Shell脚本文本三剑客之grep)
- STM32编译出现error: L6235E: More than one section matches selector - cannot all be FIRST/L
- SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series
- USB 网卡驱动数据流
- Why choose smart TV?
- 局域网SDN技术硬核内幕 11 云网融合CP的关键——层次化端口绑定
- Summary of C language knowledge involved in learning STM32F103 (link only)
- Weibo comment crawler + visualization
猜你喜欢

第10章 枚举类与注解

Principle of control system based on feedback rate

makefile模板

EfficientNet

【Unity入门计划】CreatorKitFPS:第一人称射击3D小游戏

Newton Raphson iterative method

【机器学习-白板推导系列】学习笔记---支持向量机和主成分分析法

你真的会写二分查找吗——变种二分查找
![[machine learning whiteboard derivation series] learning notes --- conditional random fields](/img/cc/87d8822b659b31360546adf057ef00.png)
[machine learning whiteboard derivation series] learning notes --- conditional random fields

Shell编程之正则表达式(Shell脚本文本三剑客之grep)
随机推荐
局域网SDN硬核技术内幕 23 展望未来——RDMA(上)
Local virtual machine initialization script
剑指 Offer 笔记: T39. 数组中出现次数超过一半的数字
STM32 compilation error: l6235e: more than one section matches selector - cannot all be first/l
STM32编译出现error: L6235E: More than one section matches selector - cannot all be FIRST/L
Arduino常见供电问题与解决
你真的会写二分查找吗——变种二分查找
w.r.t. ; i.e.; etc.; e. G. what does it mean
Everything cannot be searched for startup_ Lpc11x.s file
[machine learning whiteboard derivation series] learning notes - support vector machine and principal component analysis
Finding the finite zero point of transfer function under different sampling periods
Stm32f10x -- C Language-1
第7章 异常处理
Maker harmony OS application development training notes 01
开源flink有写holo的Datastream connector或者flink sql conn
C custom set
微机和单片机的区别
哈希表 详细讲解
USB 网卡驱动数据流
Proteus8专业版破解后用数码管闪退的解决