We are given an array A of N lowercase letter strings, all of the same length.

Now, we may choose any set of deletion indices, and for each string, we delete all the characters in those indices.

For example, if we have an array A = ["abcdef","uvwxyz"] and deletion indices {0, 2, 3}, then the final array after deletions is ["bef","vyz"].

Suppose we chose a set of deletion indices D such that after deletions, the final array has its elements in lexicographic order (A[0] <= A[1] <= A[2] ... <= A[A.length - 1]).

Return the minimum possible value of D.length.

Runtime: 8 ms, faster than 100.00% of C++ online submissions for Delete Columns to Make Sorted II.
Memory Usage: 819.2 KB, less than 48.15% of C++ online submissions for Delete Columns to Make Sorted II.
class Solution {
public:
int minDeletionSize(vector<string>& A) {
int ret = ;
bool sorted[A.size()];
for(int i=; i<A.size(); i++) sorted[i] = false;
for(int i=; i<A[].size(); i++) {
int j = ;
for(; j<A.size()-; j++) {
if(!sorted[j] && (A[j][i] > A[j+][i])) {
ret++;
break;
}
}
if(j < A.size()-) continue;
j = ;
for(; j<A.size()-; j++) {
if(A[j][i] < A[j+][i]) sorted[j] = true;
}
}
return ret;
}
};

LC 955. Delete Columns to Make Sorted II的更多相关文章

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

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

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

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

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

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

  6. 【leetcode】960. 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 cho ...

  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. Weekly Contest 111-------->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 choose an ...

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

随机推荐

  1. 3.Java集合-HashSet实现原理及源码分析

    一.HashSet概述: HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持,它不保证set的迭代顺序很久不变.此类允许使用null元素 二.HashSet的实现: 对于Ha ...

  2. Android休眠唤醒机制

    有四种方式可以引起休眠 ①在wake_unlock()中, 如果发现解锁以后没有任何其他的wake lock了, 就开始休眠 ②在定时器到时间以后, 定时器的回调函数会查看是否有其他的wake loc ...

  3. CentOS6.9 Python环境配置(python2.7、pip、virtualenv)

    python2.7 yum install -y zlib zlib-devel openssl openssl-devel mysql-devel gcc gcc-c++ wget https:// ...

  4. Window脚本学习笔记之定时关闭进程

     定时关闭进程, 从字面上即可看出操作分为两个步骤,即: 1,结合“任务计划程序”,定时. “计算机->管理->计划任务程序”,作用是让系统定时启动脚本文件(bat脚本). 2,结合“nt ...

  5. tensorflow实战笔记(20)----textRNN

    https://www.cnblogs.com/jiangxinyang/p/10208227.html https://www.cnblogs.com/jiangxinyang/p/10241243 ...

  6. Java基础 反射的基础应用和Class笔记

    笔记: /**直接 throws Exception,完美包含全部异常! * --------------------------- * Class: * 首先创建一个类, 接着编译程序: javac ...

  7. linux tcp server bind

    如果不是系统管理员: bind()函数 返回失败

  8. vue 标题上下滚屏 无缝轮播

    参考网址:https://www.jianshu.com/p/b6813193ca0d <template> <div class="wrap" :style=& ...

  9. mysql:用户自定义变量关联失效

    自定义变量的属性和限制 使用自定义变量的查询,无法使用查询缓存. 不能在使用常量或者标识列的地方使用自定义变量,例如表名.列明和LIMIT子句中. 用户自定义变量的生命周期是在一个连接中有效,所以不能 ...

  10. 通过德鲁伊druid给系统增加监控

    系统在线上运行了一段时间后,比如一年半载的,我们发现系统可能存在某些问题,比如执行系统变慢了,比如某些spring的bean无法监控各种调用情况. 触发到db的各种执行情况,这个时候,我们就需要一个工 ...