题解 | 字符串替换-双指针

字符串替换

https://www.nowcoder.com/practice/f094aed769d84cf3b799033c82fc1bf6

# -*- coding:utf-8 -*-
"""
A 
"""
class StringFormat:
    def formatString(self, A, n, arg, m):
        # write code here
        res=""
        left=0
        right=0
        while left<n and right <m:
            if A[left]=='%':
                res=res+arg[right]
                left+=2
                right+=1
            else:
                res=res+A[left]
                left+=1
        if right<n:
            temp=arg[right:]
            res+="".join(temp)
        return res 

全部评论

相关推荐

用微笑面对困难:985只有在应届生里面的优势是断层的在社招或者更远的工作中算是后续能力优先级
工作压力大,你会干什么?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务