Участник:Novitskiy97/Delete Columns to Make Sorted III

Материал из DISCOPAL
Перейти к: навигация, поиск

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

Python 3

 
class Solution:
    def minDeletionSize(self, A: List[str]) -> int:
 
        def inorder (list1, list2):
            for i in range (0, len(list1)):
                if list1[i] > list2[i]: 
                    return False
            return True 
 
        if not A: return True
 
        chars = []
        for i in range (0, len(A[0])):
            chars.append([A[j][i] for j in range (0, len(A))])
 
        LIS = [1] * len(chars)
        for i in range (1, len(chars)):
            for j in range (0, i):
                if inorder(chars[j], chars[i]): 
                    LIS[i] = max(LIS[i], 1 + LIS[j])
 
        return len(A[0]) - max(LIS)