当前位置:网站首页>力扣解法汇总944-删列造序
力扣解法汇总944-删列造序
2022-06-12 02:03:00 【失落夏天】
目录链接:
力扣编程题-解法汇总_分享+记录-CSDN博客
GitHub同步刷题项目:
https://github.com/September26/java-algorithms
原题链接:力扣
描述:
给你由 n 个小写字母字符串组成的数组 strs,其中每个字符串长度相等。
这些字符串可以每个一行,排成一个网格。例如,strs = ["abc", "bce", "cae"] 可以排列为:
abc
bce
cae
你需要找出并删除 不是按字典序升序排列的 列。在上面的例子(下标从 0 开始)中,列 0('a', 'b', 'c')和列 2('c', 'e', 'e')都是按升序排列的,而列 1('b', 'c', 'a')不是,所以要删除列 1 。
返回你需要删除的列数。
示例 1:
输入:strs = ["cba","daf","ghi"]
输出:1
解释:网格示意如下:
cba
daf
ghi
列 0 和列 2 按升序排列,但列 1 不是,所以只需要删除列 1 。
示例 2:
输入:strs = ["a","b"]
输出:0
解释:网格示意如下:
a
b
只有列 0 这一列,且已经按升序排列,所以不用删除任何列。
示例 3:
输入:strs = ["zyx","wvu","tsr"]
输出:3
解释:网格示意如下:
zyx
wvu
tsr
所有 3 列都是非升序排列的,所以都要删除。
提示:
n == strs.length
1 <= n <= 100
1 <= strs[i].length <= 1000
strs[i] 由小写英文字母组成
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/delete-columns-to-make-sorted
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
解题思路:
* 解题思路: * 比较简单,生成一个二维数组比对就好了
代码:
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;
}
}边栏推荐
- Tiobe - programming language ranking in June 2022
- Knowledge points of mall development
- 力扣解法汇总675-为高尔夫比赛砍树
- Operating mechanism of Google ads bidding
- "China Dongxin Cup" the fourth programming competition of Guangxi University (synchronous competition)
- Applets 111111
- What are the advantages of adaptive search advertising?
- 力扣解法汇总450-删除二叉搜索树中的节点
- 力扣解法汇总1022-从根到叶的二进制数之和
- Redis實現消息隊列的4種方案
猜你喜欢

Four schemes for redis to implement message queue

Summary of concrete (ground + wall) + Mountain crack data set (classification and target detection)

通用树形结构的迭代与组合模式实现方案

MySQL table common operation mind map

螺旋矩阵(技巧)

Basic use of MATLAB

C language programming classic games - minesweeping

超图倾斜数据合并根节点后转3dtiles

php开发 博客系统的公告模块的建立和引入

Ozzanmation action system based on SSE
随机推荐
In 2022, the internal promotion of the "MIHA Tour" golden, silver and silver social recruitment started in April and march! Less overtime, good welfare, 200+ posts for you to choose, come and see!
Why do we use Google search ads?
LeetCode LCP 07. 传递信息
Leetcode 45 jump game II
Summary of concrete (ground + wall) + Mountain crack data set (classification and target detection)
如何提高广告的广告评级,也就是质量得分?
2022 blind box applet app has become a new drainage outlet for enterprises
小程序111111
Four schemes for redis to implement message queue
What are the advantages of adaptive search advertising?
Basedexclassloader
Explore performance optimization! Performance improvement from 2 months to 4 hours!
android html5页面加载缓存优化
SQL calculates KS, AUC, IV, psi and other risk control model indicators
Linux(CentOS6)安装MySQL5.5版本数据库
PHP security development 13 column module of blog system
C language programming classic games - minesweeping
LeetCode Algorithm 997. 找到小镇的法官
serialization and deserialization
Graphic data analysis | business cognition and data exploration