给定由 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. 1 <= A.length <= 100
  2. 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删列造序的更多相关文章

  1. LeetCode955删列造序 ||

    问题:删列造序 || 给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等. 选取一个删除索引序列,对于 A 中的每个字符串,删除对应每个索引处的字符. 比如,有 A = [" ...

  2. [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 ...

  3. [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 ...

  4. 【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 ...

  5. 【Leetcode_easy】944. Delete Columns to Make Sorted

    problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...

  6. 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 ...

  7. [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 ...

  8. LeetCode.944-删除列保证排序(Delete Columns to Make Sorted)

    这是悦乐书的第362次更新,第389篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第224题(顺位题号是944).我们给出了一个N个小写字母串的数组A,它们的长度都相同. ...

  9. 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 ...

随机推荐

  1. Cut the Sequence

    Cut the Sequence 有一个长度为n的序列\(\{a_i\}\),现在求将其划分成若干个区间,并保证每个区间的和不超过m的情况下,每个区间的最大值的和的最小值,\(0 < N ≤ 1 ...

  2. python多线程,event,互斥锁,死锁,递归锁,信号量

    Python多线程/event 多线程-threading python的thread模块是⽐较底层的模块, python的threading模块是对thread做了⼀些包装的, 可以更加⽅便的被使⽤ ...

  3. window.location 对象中各种方法的用途

    一.简介 属性 描述 hash 从井号 (#) 开始的 URL(锚) host 主机名和当前 URL 的端口号 hostname 当前 URL 的主机名 href 完整的 URL pathname 当 ...

  4. PAT甲级——A1107 Social Clusters

    When register on a social network, you are always asked to specify your hobbies in order to find som ...

  5. 详解Android广播机制

    应用场景(常见的场景1) (1)同一应用具有多个进程的不同组件之间的消息通信 a)不同应用间的组件之间的消息通信 b)与Android系统在特定情况下的通信,如:系统开机,网络变化等 (2)同一应用内 ...

  6. USACO 2006 November Gold Fence Repair /// 贪心(有意思)(优先队列) oj23940

    题目大意: 输入N ( 1 ≤ N ≤ 20,000 ) :将一块木板分为n块 每次切割木板的开销为这块木板的长度,即将长度为21的木板分为13和8,则开销为21 接下来n行描述每块木板要求的长度Li ...

  7. shell脚本练习03--字符串

    ######################################################################### # File Name: -.sh # Author ...

  8. Arrays.asList()使用的问题

    在java语言中,把数组转换成List集合,有个很方便的方法就是 List<String> list = Arrays.asList("a","b" ...

  9. T2963 贪吃蛇【BFS,四进制状压,A*】

    Online Judge:未知 Label:BFS,四进制状压,暴力,A*,哈希,玄学. 题目描述 给定一个n*m的地图和蛇的初始位置,地图中有些位置有石头,蛇不能经过.当然蛇也不能爬到地图之外. 每 ...

  10. jQuery.event.move

    http://stephband.info/jquery.event.move/ Move events movestart Fired following touchmove or mousemov ...