当前位置:网站首页>Maximum number [abstract rules for abstract sorting]
Maximum number [abstract rules for abstract sorting]
2022-06-25 12:40:00 【REN_ Linsen】
Abstract sort
Preface
The most difficult problem is just a combination of several small problems , But there are two difficult questions , It's a math problem / Abstract problem . Such as abstract dichotomy / Abstract sort .
This article uses the maximum number to practice abstract sorting and abstract sorting rules .
One 、 The maximum number

Two 、 Abstract rules
package everyday.medium;
import java.util.ArrayList;
import java.util.List;
// The maximum number
public class LargestNumber {
/* target: Splice the numbers , Look who's big . Is to put the numbers in order , But it should be arranged according to the rules of string comparison ( The rules : Who splices the string before is bigger .), So even if the abstract sort , Abstract sorting rules . */
public String largestNumber(int[] nums) {
//todo Abstract rules , Sort by yourself , other sort
List<Integer> arr = new ArrayList<>();
// Wrap the elements into Integer, Can be transmitted to the comparator .
for (int num : nums) arr.add(num);
// Compare : Define your own comparison rules .
arr.sort((o1, o2) -> new StringBuilder().append(o2).append(o1).
compareTo(new StringBuilder().append(o1).append(o2)));
// Get the concatenated string of numbers .
StringBuilder sb = new StringBuilder();
for (Integer val : arr) sb.append(val);
// bug1: When all are 0 when , The leading will appear as 0
// return sb.toString();
return sb.charAt(0) == '0' ? "0" : sb.toString();
}
}
summary
1) Abstract sort
reference
边栏推荐
- ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
- PHP numeric array sorting and associative array sorting
- Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode
- An example of using dynamic datalist
- Qiantang Pingou source code -- Qiantang Pingou app system development source code sharing
- Is it safe to open an account and buy stocks on the Internet?
- Why do we do autocorrelation analysis? Explain application scenarios and specific operations
- Full nanny tutorial of Market Research Competition (experience sharing)
- Draw the satellite sky map according to the azimuth and elevation of the satellite (QT Implementation)
- High performance + million level Excel data import and export
猜你喜欢

ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping

Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation

Laravel excel export

顺序表的折半查找法

Penetration tool environment - installing sqli labs in centos7 environment

Embedded software development written examination and interview notes (latest update: February 17, 2022)

Flutter common commands and problems

Singleton mode in PHP to reduce memory consumption

Explain AHP in human language (very detailed principle + simple tool implementation)

Upgrade opsenssh to 8.8p1
随机推荐
PHP replaces the key of a two-dimensional array with a specified element value
Arm V7 coprocessor
Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection
The server reported an error 503 service unavailable:the system returned: (71) protocol error
Concat(), join(), reverse(), sort() method in JS array
An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
PHP appends the same elements to a two-dimensional array
Foreach method of array in JS
Heyangdao store management system -- share the development source code of heyangdao system
冷启动的最优解决方案
Huikan source code -- Huikan app system secondary development source code sharing
(5) Pyqt5 ---- another method of connecting signals and slots
Draw the satellite sky map according to the azimuth and elevation of the satellite (QT Implementation)
ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
The first techo day Tencent technology open day in 2022 will be held online on June 28
yolov5训练使用的负样本图片
Recyclerview scrolls to the specified location
Go defer little knowledge
MySQL and excel tables importing database data (Excel for MySQL)
Laravel excel export