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

 

posted on 2018-11-25 21:38  Sempron2800+  阅读(120)  评论(0编辑  收藏  举报