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.

Runtime: 8 ms, faster than 100.00% of C++ online submissions for Delete Columns to Make Sorted II.
Memory Usage: 819.2 KB, less than 48.15% of C++ online submissions for Delete Columns to Make Sorted II.
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的更多相关文章

  1. 【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 ...

  2. [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 ...

  3. 【Leetcode_easy】944. Delete Columns to Make Sorted

    problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...

  4. [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 ...

  5. 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 ...

  6. 【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 ...

  7. [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 ...

  8. 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 ...

  9. 【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 ...

随机推荐

  1. 持续集成工具FinalBuilder使用心得

    FinalBuilder 使用这款自动化创建和发布管理工具,软件开发者可以定义和维护一个可靠的以及可重复创建的程序.FinalBuilder包括集成的带有版本的控制系统,文件和目录选项,重复器,源代码 ...

  2. 快速认识Python

    1.数字和表达式 什么是表达式,1+2*3 就是一个表达式,这里的加号和乘号叫做运算符,1.2.3叫做操作数.1+2*3 经过计算后得到的结果是7,就1+2*3 = 7.我们可以将计算结果保存在一个变 ...

  3. 14_sqoop数据导入

    3.Sqoop的数据导入 “导入工具”导入单个表从RDBMS到HDFS.表中的每一行被视为HDFS的记录.所有记录都存储为文本文件的文 本数据(或者Avro.sequence文件等二进制数据) 3.1 ...

  4. python调用cv2.findContours时报错:ValueError: not enough values to unpack (expected 3, got 2)

    OpenCV旧版,返回三个参数: im2, contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_S ...

  5. linux实操_组管理

    1.文件/目录的所有者 一般为文件的创建者,谁创建了该文件,就自然成为该文件的所有者. 查看文件的所有者: 指令:ls -ahl 修改文件所有者: 指令:chown 用户名 文件名 组的创建: 指令: ...

  6. Linux卸载Django

    cd /usr/lib/python2.7/dist-packages sudo rm -rf django sudo rm Django-1.8.7.egg-info 基本命令如此,具体文件因版本有 ...

  7. Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products

    链接: https://codeforces.com/contest/1247/problem/D 题意: You are given n positive integers a1,-,an, and ...

  8. java开发时,eclipse设置编码

    修改eclipse默认工作空间编码方式,General——Workspace——Text file encoding 修改工程编码方式,右击工程——Properties——Resource——Text ...

  9. C# MVC中直接执行Js

    .NET MVC里如何在服务器端执行JS: 三种解决方案: 1.直接返回JavaScript. public ActionResult XXXAction1() {      return JavaS ...

  10. python自动华 (三)

    Python自动化 [第三篇]:Python基础-集合.文件操作.字符编码与转码.函数 1.        集合 1.1      特性 集合是一个无序的,不重复的数据组合,主要作用如下: 去重,把一 ...