【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 ...
随机推荐
- ceph-状态监测-脚本
http://www.tang-lei.com/2018/06/05/ceph-%E7%8A%B6%E6%80%81%E7%9B%91%E6%B5%8B-%E8%84%9A%E6%9C%AC/ 为了能 ...
- HihoCoder 1055 刷油漆 (树上背包)
题目:https://vjudge.net/contest/323605#problem/A 题意:一棵树,让你选择m个点的一个连通块,使得得到的权值最大 思路:树上背包,我们用一个dp数组,dp[i ...
- intellijidea 设置字体等
http://blog.csdn.net/asmcvc/article/details/17144951 1.下载安装AndroidStudio:http://developer.android.co ...
- lua实现简单
MessageManager.lua local messageManager = {mEventTable = {},mEventUserData = {}} --注册事件function mess ...
- python中chr()函数和ord()函数的用法
一,chr()函数 格式:Chr(<数值表达式>) 说明:函数返回值类型为String,其数值表达式值取值范围为0~255. 例如:Print Chr(78),结果显示:N. ...
- java并发编程笔记(十)——HashMap与ConcurrentHashMap
java并发编程笔记(十)--HashMap与ConcurrentHashMap HashMap参数 有两个参数影响他的性能 初始容量(默认为16) 加载因子(默认是0.75) HashMap寻址方式 ...
- python 3.x上安裝web.py
python 3.x上安裝web.py 查询之后,安装时使用pip3 install web.py==0.40.dev0 最終可以运行 app.py import weburls=( '/',' ...
- Flink水印机制(watermark)
Flink流处理时间方式 EventTime 时间发生的时间,例如:点击网站上的某个链接的时间 IngestionTime 某个Flink节点的source operator接收到数据的时间,例如:某 ...
- WEB服务端安全---注入攻击
注入攻击是web领域最为常见的攻击方式,其本质是把用户输入的数据当做代码执行,主要原因是违背了数据与代码分离原则,其发生的两个条件:用户可以控制数据输入:代码拼接了用户输入的数据,把数据当做代码执行了 ...
- Linux操作系统(三)_部署JDK
一.通过tar.gz压缩包安装 1.在usr目录下创建java目录 cd usr mkdir java 2.用rz命令上传tar.gz安装包到java目录 3.解压tar.gz安装包到当前目录 tar ...