Leetcode944. Delete Columns to Make Sorted删列造序
给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等。
选取一个删除索引序列,对于 A 中的每个字符串,删除对应每个索引处的字符。 所余下的字符串行从上往下读形成列。
比如,有 A = ["abcdef", "uvwxyz"],删除索引序列 {0, 2, 3},删除后 A 为["bef", "vyz"], A 的列分别为["b","v"], ["e","y"], ["f","z"]。(形式上,第 n 列为 [A[0][n], A[1][n], ..., A[A.length-1][n]])。
假设,我们选择了一组删除索引 D,那么在执行删除操作之后,A 中所剩余的每一列都必须是 非降序 排列的,然后请你返回 D.length 的最小可能值。
示例 1:
输入:["cba", "daf", "ghi"] 输出:1 解释: 当选择 D = {1},删除后 A 的列为:["c","d","g"] 和 ["a","f","i"],均为非降序排列。 若选择 D = {},那么 A 的列 ["b","a","h"] 就不是非降序排列了。
示例 2:
输入:["a", "b"] 输出:0 解释:D = {}
示例 3:
输入:["zyx", "wvu", "tsr"] 输出:3 解释:D = {0, 1, 2}
提示:
- 1 <= A.length <= 100
- 1 <= A[i].length <= 1000
class Solution {
public:
int minDeletionSize(vector<string>& A)
{
int len = A.size();
if (len == 0)
return 0;
int length = A[0].size();
int cnt = 0;
for (int i = 0; i < length; i++)
{
for (int j = 0; j < len - 1; j++)
{
if (A[j + 1][i] < A[j][i])
{
cnt++;
break;
}
}
}
return cnt;
}
};
Leetcode944. Delete Columns to Make Sorted删列造序的更多相关文章
- LeetCode955删列造序 ||
问题:删列造序 || 给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等. 选取一个删除索引序列,对于 A 中的每个字符串,删除对应每个索引处的字符. 比如,有 A = [" ...
- [Swift]LeetCode960. 删列造序 III | Delete Columns to Make Sorted III
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose an ...
- [Swift]LeetCode955. 删列造序 II | Delete Columns to Make Sorted II
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose an ...
- 【leetcode】955. Delete Columns to Make Sorted II
题目如下: We are given an array A of N lowercase letter strings, all of the same length. Now, we may cho ...
- 【Leetcode_easy】944. Delete Columns to Make Sorted
problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...
- LC 955. Delete Columns to Make Sorted II
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose an ...
- [Swift]LeetCode944. 删除列以使之有序 | Delete Columns to Make Sorted
We are given an array A of N lowercase letter strings, all of the same length. Now, we may choose an ...
- LeetCode.944-删除列保证排序(Delete Columns to Make Sorted)
这是悦乐书的第362次更新,第389篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第224题(顺位题号是944).我们给出了一个N个小写字母串的数组A,它们的长度都相同. ...
- LeetCode 944 Delete Columns to Make Sorted 解题报告
题目要求 We are given an array A of N lowercase letter strings, all of the same length. Now, we may choo ...
随机推荐
- leetcood学习笔记-55-跳跃游戏
题目描述: 第一次提交: class Solution: def canJump(self, nums: List[int]) -> bool: if len(nums)<=1: retu ...
- SpringCloudConfig
方便服务配置文件统一管理,实时更新 组成 在spring cloud config组件中,分两个角色,一是config server,二是config client Config Server是一个可 ...
- Delphi 查找标题已知的窗口句柄,遍历窗口控件句柄
有了回调函数的概念及上面的例子,我们可以继续了.其实想要找到一个标题已知的窗口句柄,用一个API函数就可以了:FindWindow.其函数原形是:function FindWindow(lpClass ...
- text-html 转译
var HtmlUtil = { 2 /*1.用浏览器内部转换器实现html编码(转义)*/ 3 htmlEncode:function (html){ 4 //1.首先动态创建一个容器标签元素,如D ...
- 软件-开发软件:Android Studio
ylbtech-软件-开发软件:Android Studio Android Studio 是谷歌推出的一个Android集成开发工具,基于IntelliJ IDEA. 类似 Eclipse ADT, ...
- latex ctex 的section不能写中文, /href
问题描述:再使用超链接 /href 后发现section{}不能写入中文,以前是好使的,经过查询验证,需要在引导区里加入 \hypersetup{CJKbookmarks=true} 即可恢复正常.
- [kuangbin带你飞]专题一 简单搜索 - F - Prime Path
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #i ...
- PAT甲级——A1131 Subway Map【30】
In the big cities, the subway systems always look so complex to the visitors. To give you some sense ...
- Invalid bound statement (not found)之idea打包maven项目问题
开发的一个maven项目,之前在Eclipse中,maven打包部署完后一切正常,后来转到idea中开发,再用maven打包部署后, 一直报 Invalid bound statement (not ...
- 侧滑关闭Activity的解决方案——SwipeBackLayout
项目地址:ikew0ng/SwipeBackLayout: An Android library that help you to build app with swipe back gesture. ...