题目如下:

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. 1 <= A.length <= 100
  2. 1 <= A[i].length <= 1000

解题思路:如果不考虑时间复杂度,那么这题的级别应该是Easy,而不是Medium。O(n^2)的方法也很简单,遍历每一组序列,如果不满足递增则要删除这一组。

代码如下:

class Solution(object):
def minDeletionSize(self, A):
"""
:type A: List[str]
:rtype: int
"""
for i in range(len(A)):
A[i] += '{'
res = 0
for j in range(len(A[0])):
for i in range(len(A)-1):
if A[i][j] > A[i+1][j]:
res += 1
break
return res

【leetcode】944. Delete Columns to Make Sorted的更多相关文章

  1. 【LeetCode】944. Delete Columns to Make Sorted 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

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

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

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

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

  5. 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)

    [LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...

  6. 【LeetCode】154. Find Minimum in Rotated Sorted Array II 解题报告(Python)

    [LeetCode]154. Find Minimum in Rotated Sorted Array II 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...

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

  8. 【LeetCode】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...

  9. 【LeetCode】450. Delete Node in a BST 解题报告 (Python&C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 日期 题目地址:https://leetcode ...

随机推荐

  1. Bootstrap的本地引入

    今天用前端框架时选择了Bootstrap,然后东西都下好了本地就是引入不进去. 查了一下发现必须jquery要在BootStrap之前引入,然后我更改了引入顺序,发现还是不行 <script s ...

  2. Python基础教程(021)--Pycharm简介

    前言 学习Pycharm开发工具 内容 项目:就是一个功能复杂的软件 目标 必须掌握的工具

  3. Alex and Number

    Alex and Number 时间限制: 1 Sec  内存限制: 128 MB提交: 69  解决: 12[提交][状态] 题目描述 Alex love Number theory. Today ...

  4. 使用nsenter进入docker容器后端报错 mesg: ttyname failed: No such file or directory

    通过nsenter 进入到docker容器的后端总是报下面的错,, [root@devdtt ~]# docker inspect -f {{.State.Pid}} mynginx411950 [r ...

  5. rabbitmq for C#的异步消息确认机制

    代码: using (var conn = RabbitmqHelper.GetConnection()) { using (var channel = conn.CreateModel()) { / ...

  6. html常用代码

    <marquee width="70%" scrollamount="2">大家好</marquee>    // 大家好 字符从左到右 ...

  7. [USACO 07NOV]电话线Telephone Wire

    题目描述 Farmer John's cows are getting restless about their poor telephone service; they want FJ to rep ...

  8. 热修复设计之AOT/JIT&dexopt 与 dex2oat (一)

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680本篇文章将先从AOT/JIT&dexopt 与 dex2o ...

  9. Codeforces 500D New Year Santa Network(树 + 计数)

    D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  10. HDU 6469 /// 二分

    题目大意: 分裂怪有1到n种等级, 第1级的分裂怪称为原子怪,它不会分裂,被击杀时会产生a[1]点经验: 而第k级的分裂怪死亡时则会分裂成a[k]个第k - 1级的分裂怪. 一个体力可以杀死一个怪物. ...