题解 | #字符串变形#

字符串变形

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

class Solution {
  public:
    string trans(string s, int n) {
        for (int i = 0 ; i < n; ++i) {
            if (s[i] != ' ') {
                int b = i, e = i;
                while (s[e] != ' ' && e < n) {
                    s[e] = islower(s[e]) ? toupper(s[e]) : tolower(s[e]);
                    ++e;
                }
                int e_bak = e;
                --e;
                while (b < e) {
                    swap(s[b], s[e]);
                    ++b;
                    --e;
                }
                i = e_bak;
            }
        }
        reverse(s.begin(), s.end());
        return s;
    }
};
全部评论

相关推荐

10-16 15:48
算法工程师
点赞 评论 收藏
分享
FFFoly:我也是,现在已经到了学长说的 能面试侃侃而谈的阶段了,但是已经没有公司给我面了
远程面试的尴尬瞬间
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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