—Easy

https://leetcode.com/problems/delete-columns-to-make-sorted/

944. 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不会影响判定结果正确性,好评

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-01-27
  • 2021-12-05
  • 2021-12-22
  • 2022-12-23
  • 2021-06-29
猜你喜欢
  • 2021-08-07
  • 2022-12-23
  • 2021-06-26
  • 2022-01-02
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案