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 ...
随机推荐
- NORDIC BLE升级
NRF52832 SDK15.3.0 概述: 所谓DFU(Device Firmware Update),就是设备固件升级的意思,而OTA是DFU的一种类型,准确说,OTA的全称应该是OTA DFU, ...
- C# UDP发送和接收
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...
- U盘装manjaro 18报Python error in job “initcpio”
更新: 还是不行,大家再找别的方法. 以下内容仅做参考,意义不大. U盘安装 用rufus做U盘,写入选DD模式,比ISO模式可靠点. 错误解决 报错信息: Error installing Manj ...
- [Python] Codecombat攻略 远边的森林 Forest (1-40关)
首页:https://cn.codecombat.com/play语言:Python 第二界面:远边的森林Forest(40关)时间:2-6小时内容:if/else.关系操作符.对象属性.处理输入网页 ...
- 获取当前日期或者某个日期相隔N天内的全部日期以及星期几
业务需要需要获取当前日期相隔30天内的全部日期以及星期几,没插件因此特地写了一个: /* 说明:获取当前日期或者某个日期相隔N天内的全部日期以及星期几 使用: let test = new getdi ...
- Redis单实例数据迁移到集群
环境说明 单机redis redis集群 192.168.41.101:7000 master 192.168.41.101:7001 master 192.168.41.102:7000 maste ...
- Vue-cli中的proxyTable解决开发环境的跨域问题
https://blog.csdn.net/u012149969/article/details/80288126 https://vuejs-templates.github.io/webpack/ ...
- Redis做消息队列
1.连接从Redis中获取日志文件并存储到ES中 [root@Logstash ~]# vim /usr/local/logstash/config/redis.conf input { be ...
- 学习Python编程的最好的几本书
读书是汲取某个特定学科的知识以及更深入的理解该学科的最好的方式.在这个科技世界,通晓计算机系统各个不同的技术领域是至关重要的.其中最重要的内容之一便是计算机程序语言.现今,计算机中存在许多不同类型的程 ...
- linux命令集合(二)
yum源的配置 yum 得配置yum源,配置阿里云的 两个 yum源 ,阿里云的yum源中,会有 mariadb的软件包 阿里云的yum仓库中,mariadb版本如下 mariadb ...