【leetcode】944. Delete Columns to Make Sorted
题目如下:
We are given an array
AofNlowercase 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
Dsuch 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: 1Example 2:
Input: ["a","b"]
Output: 0Example 3:
Input: ["zyx","wvu","tsr"]
Output: 3Note:
1 <= A.length <= 1001 <= 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的更多相关文章
- 【LeetCode】944. Delete Columns to Make Sorted 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
- 【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 ...
- 【Leetcode_easy】944. Delete Columns to Make Sorted
problem 944. Delete Columns to Make Sorted 题意:其实题意很简单,但是题目的description给整糊涂啦...直接看题目标题即可理解. solution: ...
- 【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 ...
- 【LeetCode】153. Find Minimum in Rotated Sorted Array 解题报告(Python)
[LeetCode]153. Find Minimum in Rotated Sorted Array 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode. ...
- 【LeetCode】154. Find Minimum in Rotated Sorted Array II 解题报告(Python)
[LeetCode]154. Find Minimum in Rotated Sorted Array II 解题报告(Python) 标签: LeetCode 题目地址:https://leetco ...
- 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】237. Delete Node in a Linked List 解题报告 (Java&Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 设置当前节点的值为下一个 日期 [LeetCode] ...
- 【LeetCode】450. Delete Node in a BST 解题报告 (Python&C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 日期 题目地址:https://leetcode ...
随机推荐
- 【leetcode】892. Surface Area of 3D Shapes
题目如下: 解题思路:对于v = grid[i][j],其表面积为s = 2 + v*4 .接下来只要在判断其相邻四个方向有没有放置立方体,有的话减去重合的面积即可. 代码如下: class Solu ...
- Jenkins之配置GitHub-Webhook2
什么是持续集成(Continuous integration) 提出者Martin Fowler本人对持续集成是这样定义的:持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作,通常每个成员每 ...
- Linux任务计划at
Linux任务计划at 一Linux任务计划介绍 Linux任务计划.周期性任务执行at:未来的某时间点执行一次任务batch:系统自行选择空闲时间去执行此处指定的任务cron:周期性运行某任务 二a ...
- idea将本地项目推送到git远程库
如何将本地项目推送到github远程仓库? 1. 在github上创建一个仓库,取名mybatis 2. 在idea中将项目交由git管理 注意,文件名会变红了, 说明这些文件在git工作区,但还没规 ...
- 浅谈js for循环输出i为同一值的问题(闭包解决)
1.最近开发中遇到一个问题,为什么每次输出都是5,而不是点击每个p,就alert出对应的1,2,3,4,5. <html> <head> <meta http-equiv ...
- operator函数操作符
函数操作数() 可以实现将对象当函数使用. class Square{ public: double operator()(double x)const{return x*x;} };
- 汇编 “ program has no starting address ”解决方法
- 某些 UI效果 实现思路
一.日历组件: https://blog.csdn.net/amork/article/details/7257212 二.瀑布流 三.轮播图:轮播图已经用的很多了,结构也简单就不去将了. 四.分页组 ...
- 3 August
P1013 进制位 结论:加法必为 \(n-1\) 进制:\({(n-1)}^1\) 位必为数字 1:\(0+0=0\). 模拟.字符串. #include <cstdio> #inclu ...
- [CSP-S模拟测试]:beauty(搜索)
题目描述 距离产生美.一棵包含$n$个点的树,有$2k$个不同的关键点,我们现在需要将这些点两两配对,对于一种形如:$$(u_1,v_1),(u_2,v_2),...,(u_k,v_k)$$的配对方案 ...