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 ...
随机推荐
- 初识cv
验证码识别的一般套路: 灰度化.图像处理.二值化.选算法.训练.评估调整参数.预测,当然,我在这里二值化与处理的顺序换了一下,灵活处理哈 1 显示图片轮廓 img = cv2.Canny(img,25 ...
- go语言interface学习
Go 中的 interface 所具有的最基本的功能:作为一种 abstract type,实现各种 concrete type 的行为统一. interface是一种类型.只有是实例化后才能调用in ...
- MySQL数字类型int与tinyint、float与decimal如何选择
最近在准备给开发做一个mysql数据库开发规范方面培训,一步一步来,结合在生产环境发现的数据库方面的问题,从几个常用的数据类型说起. int.tinyint与bigint 它们都是(精确)整型数据类型 ...
- Java之IO学习
知其然也要知其所以然,最近对IO流莫名的感觉时候充充电了,所以上网拜读了大神的文章.在学习过程中我找到了一篇很系统很详细的文章贴出来. 声明一下这是转载的文章 原文:https://www.cnbl ...
- (13)input输入函数
(1)input 等待用户动态输入一个值,注意得到的值是一个字符串类型 提示用户输入用户名和密码: 如果用户名是admin , 并且密码是000 , 提示用户恭喜你,登陆成功 否则提示用户名或密码错误 ...
- Pycharm----默认字体大小的设置
设定前 设定后,修改字体的大小为:15号 设置方式:按照截图操作选择后,点击”apply“即可
- 第107题:二叉树的层次遍历II
一. 问题描述 给定一个二叉树,返回其节点值自底向上的层次遍历. (即按从叶子节点所在层到根节点所在的层,逐层从左向右遍历) 例如: 给定二叉树 [3,9,20,null,null,15,7], 3 ...
- 配置IIS使其支持APK文件的下载
在管理工具里打开Internet 信息服务(IIS)管理器.然后选择需要配置的网站. 右侧的界面中会显示该网站的所有功能配置,我们选择并点击进入“MIME类型” 在左侧的操作区选择点击“添加”MI ...
- Codeforces Round #551 (Div. 2) F. Serval and Bonus Problem (DP/FFT)
yyb大佬的博客 这线段期望好神啊... 还有O(nlogn)FFTO(nlogn)FFTO(nlogn)FFT的做法 Freopen大佬的博客 本蒟蒻只会O(n2)O(n^2)O(n2) CODE ...
- Python14__网络SOCKET