当前位置:网站首页>Summary of force deduction solution 944- deletion of sequence
Summary of force deduction solution 944- deletion of sequence
2022-06-12 02:08:00 【Lost summer】
Directory links :
Force buckle programming problem - The solution sums up _ Share + Record -CSDN Blog
GitHub Synchronous question brushing items :
https://github.com/September26/java-algorithms
Original link : Power button
describe :
Here you are n An array of lowercase character strings strs, Where each string is of equal length .
These strings can each be one line , Form a grid . for example ,strs = ["abc", "bce", "cae"] Can be arranged as :
abc
bce
cae
You need to find and delete Not in ascending dictionary order Column . In the above example ( Subscript from 0 Start ) in , Column 0('a', 'b', 'c') And column 2('c', 'e', 'e') They are arranged in ascending order , And column 1('b', 'c', 'a') No , So delete the column 1 .
Return the number of columns you need to delete .
Example 1:
Input :strs = ["cba","daf","ghi"]
Output :1
explain : The grid diagram is as follows :
cba
daf
ghi
Column 0 And column 2 In ascending order , Danlie 1 No , So just delete the columns 1 .
Example 2:
Input :strs = ["a","b"]
Output :0
explain : The grid diagram is as follows :
a
b
Only Columns 0 This column , And have been arranged in ascending order , So you don't have to delete any columns .
Example 3:
Input :strs = ["zyx","wvu","tsr"]
Output :3
explain : The grid diagram is as follows :
zyx
wvu
tsr
all 3 The columns are arranged in non ascending order , So you have to delete .
Tips :
n == strs.length
1 <= n <= 100
1 <= strs[i].length <= 1000
strs[i] It's made up of lowercase letters
source : Power button (LeetCode)
link :https://leetcode.cn/problems/delete-columns-to-make-sorted
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Their thinking :
* Their thinking : * Relatively simple , Just generate a two-dimensional array comparison
Code :
public class Solution944 {
public int minDeletionSize(String[] strs) {
int num = 0;
char[][] charss = new char[strs.length][strs[0].length()];
for (int i = 0; i < strs.length; i++) {
charss[i] = strs[i].toCharArray();
}
for (int i = 0; i < charss[0].length; i++) {
int last = 0;
for (char[] chars : charss) {
char c = chars[i];
if (c >= last) {
last = c;
continue;
}
num++;
break;
}
}
return num;
}
}边栏推荐
- Summary of concrete (ground + wall) + Mountain crack data set (classification and target detection)
- el-upload上传文件
- MySQL table common operation mind map
- SwiftyJSON解析本地JSON文件
- Google Ads 的优势
- Leetcode 1005 maximized array sum after K negations
- 消防栓监测系统毕业设计---论文(附加最全面的从硬件电路设计->驱动程序设计->阿里云物联网搭建->安卓APP设计)
- 力扣解法汇总386-字典序排数
- Is the bidding price fixed for each click?
- 力扣解法汇总427-建立四叉树
猜你喜欢

MySQL advanced knowledge points

leetcode:6. Zigzag transformation

消防栓监测系统毕业设计---论文(附加最全面的从硬件电路设计->驱动程序设计->阿里云物联网搭建->安卓APP设计)

ACL 2022 | 预训练语言模型和图文模型的强强联合

Graphical data analysis | data analysis tool map

el-upload上传文件

Graphical data analysis | business analysis and data mining

How WPS inserts a directory and the operating steps for quickly inserting a directory

matplotlib. pyplot. Bar chart (II)

leetcodeSQL:612. Nearest distance on plane
随机推荐
Oracle 11g graphic download installation tutorial (step by step)
"China Dongxin Cup" the fourth programming competition of Guangxi University (synchronous competition)
入手Ticwatch2
Introduction to SVM
竞价广告每次点击出价多少钱是固定的吗?
Advantages of Google ads
Graphical data analysis | data analysis tool map
力扣解法汇总883-三维形体投影面积
Graphical data analysis | business analysis and data mining
DDD的分层架构
国资入股,建业地产这回稳了吗?
Force deduction solution summary 905- array sorted by parity
力扣解法汇总933-最近的请求次数
2022西式面点师(技师)复训题库及在线模拟考试
Force deduction solution summary 388- longest absolute path of file
力扣解法汇总824-山羊拉丁文
leetcodeSQL:612. Nearest distance on plane
力扣解法汇总449-序列化和反序列化二叉搜索树
如何最大化的利用各种匹配方式? ——Google SEM
力扣解法汇总388-文件的最长绝对路径