题目如下:

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 = 0for j in range(len(A[0])):for i in range(len(A)-1):if A[i][j] > A[i+1][j]:res += 1breakreturn res

转载于:https://www.cnblogs.com/seyjs/p/9982856.html

【leetcode】944. Delete Columns to Make Sorted相关推荐

  1. 【Leetcode】1474. Delete N Nodes After M Nodes of a Linked List

    题目地址: https://leetcode.com/problems/delete-n-nodes-after-m-nodes-of-a-linked-list/ 给定一个链表,再给定两个正整数mm ...

  2. 【LeetCode】154. Find Minimum in Rotated Sorted Array II (3 solutions)

    Find Minimum in Rotated Sorted Array II Follow up for "Find Minimum in Rotated Sorted Array&quo ...

  3. 【LeetCode】1631. Path With Minimum Effort 最小体力消耗路径(Medium)(JAVA)每日一题

    [LeetCode]1631. Path With Minimum Effort 最小体力消耗路径(Medium)(JAVA) 题目描述: You are a hiker preparing for ...

  4. HOT 100(61~80)【LeetCode】

    HOT 100(61~80)[LeetCode] HHOT 100(61~80) 前言 推荐 207. 课程表[中等] 208. 实现 Trie (前缀树)[中等] 215. 数组中的第K个最大元素[ ...

  5. 【Leetcode】100. 相同的树

    题目 给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1/ \ / \2 3 2 3[1,2,3], [1 ...

  6. 【leetcode】85. Maximal Rectangle 0/1矩阵的最大全1子矩阵

    1. 题目 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...

  7. 【leetcode】486. Predict the Winner

    题目如下: Given an array of scores that are non-negative integers. Player 1 picks one of the numbers fro ...

  8. 【leetcode】132. Palindrome Partitioning II

    题目如下: 解题思路:本题是[leetcode]131. Palindrome Partitioning的升级版,要求的是求出最小cuts,如果用[leetcode]131. Palindrome P ...

  9. 【leetcode】86. Partition List

    题目如下: Given a linked list and a value x, partition it such that all nodes less than x come before no ...

最新文章

  1. python简单装饰器_python装饰器的简单示例
  2. Logback 配置文件这么写,TPS 提高 10 倍!
  3. SAP常见的几个接口技术的区别
  4. Net中如何操作IIS
  5. css flex排序居中
  6. ABAP单元帮助类的两种使用方式
  7. 最新 | 2018年无人机研发热点
  8. (数据科学学习手札30)朴素贝叶斯分类器的原理详解Python与R实现
  9. 自如CEO熊林接任董事长
  10. Android 自定义View可拖动移动位置及边缘拉伸放大缩小
  11. 阿里云云原生一体化数仓入选 2022数博会“十佳大数据案例”
  12. 51单片机驱动继电器模块点灯
  13. ElementUI修改Dialog的标题样式
  14. tp6常用功能整理(本人刚学习tp6遇到的常见问题)
  15. 笔记01-如何创建一个vue3的项目
  16. c4d安装完 只有语言英文的,为何我将显示语言设置成英文后开始菜单分类还依然显示为中文?...
  17. 基于Kotlin实现学生信息管理系统【100010063】
  18. 陈天奇:机器学习科研的十年
  19. PM2.5传感器通过树莓派推送到ThingsPanel
  20. 十大众筹PC:硅谷新生代如何打造下一代计算机

热门文章

  1. python太阳花的编程_python大佬养成计划----HTML DOM
  2. 通过internet在计算机之间以用户名,第7_8章_计算机网络与internet应用.doc
  3. java高级特性2,Java高级特性 2
  4. 简易嵌入式管理平台 C 实现
  5. php lang无效,详解 Go 中的不可变类型
  6. c语言测试代码怎么写,初学C语言,写了一个测试手速的工具,代码发上来,存着。。...
  7. layui循环数据并渲染_layui使用表格渲染获取行数据的例子
  8. mysql 查询优化实验报告_Mysql查询优化小结
  9. html 乱码_html小坑:网页变成乱码
  10. Verilog设计实例(6)基于Verilog的各种移位寄存器实现