1 Star 0 Fork 0

yuhang2__2/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
delete-columns-to-make-sorted.py 735 Bytes
一键复制 编辑 原始数据 按行查看 历史
# Time: O(n * l)
# Space: O(1)
class Solution(object):
def minDeletionSize(self, A):
"""
:type A: List[str]
:rtype: int
"""
result = 0
for c in xrange(len(A[0])):
for r in xrange(1, len(A)):
if A[r-1][c] > A[r][c]:
result += 1
break
return result
# Time: O(n * l)
# Space: O(n)
import itertools
class Solution2(object):
def minDeletionSize(self, A):
"""
:type A: List[str]
:rtype: int
"""
result = 0
for col in itertools.izip(*A):
if any(col[i] > col[i+1] for i in xrange(len(col)-1)):
result += 1
return result
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yuhang2__2/LeetCode-Solutions.git
git@gitee.com:yuhang2__2/LeetCode-Solutions.git
yuhang2__2
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助