LintCode:字符大小写排序

来源:互联网 发布:影像混搭软件 编辑:程序博客网 时间:2024/05/03 09:56

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
0 0
原创粉丝点击