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 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.
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的更多相关文章
- 【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 ...
- [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_easy】944. Delete Columns to Make Sorted
problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...
- [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 ...
- 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 ...
- 【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 ...
- [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 ...
- 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 ...
- 【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 ...
随机推荐
- spring-security2配置精讲(转载)
本文转载自牛人downpour的帖子: http://www.iteye.com/topic/319965 Spring 论坛上看了不少Spring Security的相关文章.这些文章基本上都还是基 ...
- js中的in
in这个操作符平时我们可能用的不多,但是一旦有需要我觉得还是很有用的,昨天在in操作符中栽了一个坑,写个博客纪念一下 var json = {a:1,b:2,c:3}; console.log('a' ...
- #Python语言程序设计Demo - 七段数码管绘制
Python设计七段数码管绘制 单个数码管效果: 设计总数码管效果: Pyhton 编程: #七段数码管绘制 import turtle as t import time as T def drawG ...
- pipenv安装报错ReadTimeoutError
原因:pip下载源默认设置为国外 解决:将pip下载源切换为国内地址 操作: 在C:\Users\Administrator\下新建pip文件夹,在创建pip.ini文件,拷贝下面代码进去,保存 切换 ...
- nginx添加模块记录
查看现有nginx的编译参数: [root@iZbp1d0dkjhfmxnxp7wuhmZ nginx-1.12.2]# nginx -Vnginx version: nginx/1.12.2buil ...
- css引用优先级
/***************************************css注意事项*******************************************/ 浏览器优先级:设 ...
- python_datetime模块和time模块
1.datetime模块 获取当前时间: import datetime # 获取当前时间 ctime = datetime.datetime.now() print(ctime) 只显示:年-月-日 ...
- c++对c的扩展----引用类型
变量是一个内存的别名,程序通过变量名使用内存空间,当然一个内存空间可以起多个别名么? 答案:可以,这就是c++中引用的由来,引用就是给变量起别名 引用是c++的概念!!!况且声明引用的符号&十 ...
- map填充bean赋值,包括父类全部填充。
有不少工具类给bean填充值.但是填充,很多都是只能填充到当前类的对象.经过需求修改,做了个工具类: import java.lang.reflect.Field; import java.lang. ...
- linux下解决安装jdk后‘环境变量’不生效的问题
1.是否需要配置环境变量,主要看java -version 显示的版本是否为你期望的版本: (1)不需要配置环境变量的情况 使用java -version查看,版本显示正好是你刚刚安装的版本,这一般为 ...