—Easy
https://leetcode.com/problems/delete-columns-to-make-sorted/
Code:
class Solution:
def minDeletionSize(self, A) -> int:
ans = [1]*len(A[0])
tmp = A[0]
for ls in A[1:]:
for i in range(len(ls)) :
if ans[i] == 1 and ord(ls[i]) < ord(tmp[i]):
ans[i] = 0
print(tmp[i],ls[i])
tmp = ls
ans_count = 0
for elt in ans:
if elt == 0:
ans_count += 1
return ans_count
# s = Solution()
# print(s.minDeletionSize(["zyx","wvu","tsr"]))
思路:
1.第一次错是因为没注意到ans 的length
2.第二次是因为忘记了改回第一次为第一次操作所做...
3.意外发现:其他不影响返回值的print不会影响判定结果正确性,好评