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 any set of deletion indices, and for each string, we delete all the characters in those indices.
For example, if we have a string "
abcdef
"
and deletion indices {0, 2, 3}
, then the final string after deletion is "
bef
"
.
Suppose we chose a set of deletion indices D
such that after deletions, each remaining column in A is in non-decreasing sorted order.
Formally, the c
-th column is [A[0][c], A[1][c], ..., A[A.length-1][c]]
Return the minimum possible value of D.length
.
Example 1:
Input: ["cba","daf","ghi"]
Output: 1
Example 2:
Input: ["a","b"]
Output: 0
Example 3:
Input: ["zyx","wvu","tsr"]
Output: 3
Note:
1 <= A.length <= 100
1 <= A[i].length <= 1000
Approach #1:
class Solution {
public:
int minDeletionSize(vector<string>& A) {
int size = A.size();
int len = A[0].size();
int ans = 0;
for (int i = 0; i < len; ++i) {
for (int j = 0; j < size-1; ++j) {
if (A[j][i] > A[j+1][i]) {
ans++;
break;
}
}
}
return ans;
}
};
Weekly Contest 111-------->944. Delete Columns to Make Sorted的更多相关文章
- 【Leetcode_easy】944. Delete Columns to Make Sorted
problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...
- 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】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 ...
- 【LeetCode】944. Delete Columns to Make Sorted 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- Leetcode 944. Delete Columns to Make Sorted
class Solution: def minDeletionSize(self, A: List[str]) -> int: ans = 0 for j in range(len(A[0])) ...
- 【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 ...
- 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]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】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 ...
随机推荐
- 解决怎样监听Activity切换
本篇博文在我之前的博文中已经提到了,可是监听Activity切换又能够作为一个单独的内容来叙述,因此这里又单独拿了出来进行赘述. Activity的切换无非有两种.第一种:启动或者创建一个新的Acti ...
- 计算IMEI号的校验位
计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...
- php 数组转xml 数组转json xml转数组 json转数组
array->xml <?php function array2xml($array, $tag) { function ia2xml($array) { $xml="" ...
- CSS伪类:before 和 :after
CSS用了许久,对一些伪类熟视无睹,从不想着去搞清楚一下.比如说这个 :before :after 其实,:before 表示该标记前面的样式,反之 :after 代表设置后面的样式.网页上常常看到有 ...
- Struts2中的数据类型转换
Struts2对数据的类型转换 一.Struts2中自带类型转换拦截器 Struts2内部提供了大量转换器,用来完成数据类型转换的问题,有如下 * boolean 和 Boolean * char和 ...
- Android笔记之强大的buildConfigField
在进行项目开发或维护时,经常会遇到调试和发布所用到的参数值不一致的情况 例如,服务器会分测试和正式,为了能方便地更改(自动更换)服务器地址,buildConfigField就派上用场了 以前都是手动更 ...
- 配置tomcat,访问端口改为80
首先:找到tomcat的的config文件夹下的server.xml文件: 编辑server.xml 保存server.xml文件,重启tomcat服务器,即可. 亲测好使.
- 20170228 交货单过账增强 MV50AFZ1
MV50AFZ1 这个程序里面找个FORM 用户出口, FORM USEREXIT_SAVE_DOCUMENT_PREPARE. 用户出口如下: 例:需求: 开发要求:制作交货单的人员,需要同 ...
- linux常用命令与技巧(不断添加与更新)
linux常用命令:linux命令有很多,不去做全面的介绍与总结,这里只是记录在使用linux过程中遇到的常用命令和技巧,以便以后查阅. # mkdir -p /usr/local/src/ ##递归 ...
- 使用dbms_stats.gather_table_stats调整表的统计信息
创建实验表,插入10万行数据 SQL> create table test (id number,name varchar2(10)); Table created. SQL> decla ...