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 ...
随机推荐
- 说说设计模式~单件模式(Singleton)
单件模式(Singleton)要求一个类有且仅有一个实例,并且提供了一个全局的访问点. 从概念上来研究一下它的实现,不考虑线程安全 1 public sealed class Singlton 2 { ...
- Python3做采集
出于某些目的,需要在网上爬一些数据.考虑到Python有各种各样的库,以前想试试Pycharm这个IDE,就决定用它了.首先翻完<深入Python3>这本书,了解了它的语法之类的.下面就开 ...
- 美拍、秒拍中安卓、IOS短视频拍摄的一些关键技术
在发布<EasyDarwin开发出类似于美拍.秒拍的短视频拍摄SDK:EasyVideoRecorder>后,今天有人问到像美拍.秒拍这些短视频拍摄是怎么做到的,包括其中的一些功能,例如: ...
- 九度OJ 1131:合唱队形 (DP、最长上升下降序列)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2865 解决:881 题目描述: N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学不交换位置就能排成合唱队形. ...
- 15款创建美丽幻灯片的 jQuery 插件
1. Skippr Skippr 是一个超级简单的 jQuery 幻灯片插件.仅仅是包含你的网页中引入 jquery.skippr.css 和 jquery.skippr.js 文件就能使用了. Sk ...
- linux mount的安装配置
1.首先需要安装nfs-utils 和 portmap: yum install nfs-utils portmap (安装软件,也可直接安装 yum install nfs* portmap)chk ...
- sdutoj 2373 Black and white painting( 规律统计计算 3Y )
Black and white painting 题目描述 You are visiting the Centre Pompidou which contains a lot of modern pa ...
- tflearn数据预处理
#I just added a function for custom data preprocessing, you can use it as: minmax_scaler = sklearn.p ...
- Jquery 获取所有对象的第一个子元素
转自:http://blog.sina.com.cn/s/blog_5fdbd0410100pmnn.html <ul> <li>John</li> <l ...
- Java面向对象的三大特征详解
一.封装(Encapsulation) 封装也称信息隐藏,是指利用抽象数据类型把数据和基于数据的操作封装起来,使其成为一个不可分割的整体,数据隐藏在抽象数据内部,尽可能的隐藏数据细节,只保 ...