public class Solution { public int MinDeletionSize(string[] A) { var result = 0; for (int j = 0; j < A[0].Length; j++) { for (int i = 1; i < A.Length; i++) { if (A[i - 1][j] > A[i][j]) { result++; break; } } } return result; } }
补充一版python3的实现代码:
class Solution: def minDeletionSize(self, A): count = 0 len1 = len(A) len2 = len(A[0]) for j in range(len2): a = "" b = "" for i in range(len1): if(a == ""): a = A[i][j] else: b = A[i][j] if(a > b): count += 1 break a = b return count