LintCode:字符大小写排序

LintCode:字符大小写排序

双指针。

class Solution:
    """ @param chars: The letters array you should sort. """
    def sortLetters(self, chars):
        # write your code here
        m = 0
        n = len(chars) - 1
        while(m < n):
            while chars[m] > 'Z' and m < n:
                m += 1
            while chars[n] <= 'Z' and m < n:
                n -= 1
            chars[m], chars[n] = chars[n], chars[m]
            m = m + 1
            n = n - 1

你可能感兴趣的:(LintCode:字符大小写排序)