美文网首页人民广场
python实现小写字母在前大写字母在后的字符串

python实现小写字母在前大写字母在后的字符串

作者: 小云1121 | 来源:发表于2021-04-30 11:47 被阅读0次

    一个字符串为大小写字母混乱排序,最小时间复杂度实现一个前序为都为小写字母后序为大写字母的字符串

    #! /bin/python3
    
    def get_str(a):
        a=list(a)
        le=len(a)
        m=0
        n=le-1
        while(m<n):
            while(a[m].islower() and m<n):
                m+=1
            while(a[n].isupper() and m<n):
                n-=1
            a[m],a[n]=a[n],a[m]
        a=''.join(a)
        return a
    if __name__ == '__main__':
        a='BAsaBsasKSAs'
        print(get_str(a))
    

    相关文章

      网友评论

        本文标题:python实现小写字母在前大写字母在后的字符串

        本文链接:https://www.haomeiwen.com/subject/omjnrltx.html