Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
delete-columns-to-make-sorted-ii.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
kamyu 提交于 2018-12-09 21:31 +08:00 . Update delete-columns-to-make-sorted-ii.py
# Time: O(n * l)
# Space: O(n)
class Solution(object):
def minDeletionSize(self, A):
"""
:type A: List[str]
:rtype: int
"""
result = 0
unsorted = set(range(len(A)-1))
for j in xrange(len(A[0])):
if any(A[i][j] > A[i+1][j] for i in unsorted):
result += 1
else:
unsorted -= set(i for i in unsorted if A[i][j] < A[i+1][j])
return result
# Time: O(n * m)
# Space: O(n)
class Solution2(object):
def minDeletionSize(self, A):
"""
:type A: List[str]
:rtype: int
"""
result = 0
is_sorted = [False]*(len(A)-1)
for j in xrange(len(A[0])):
tmp = is_sorted[:]
for i in xrange(len(A)-1):
if A[i][j] > A[i+1][j] and tmp[i] == False:
result += 1
break
if A[i][j] < A[i+1][j]:
tmp[i] = True
else:
is_sorted = tmp
return result
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助