2109. 向字符串添加空格

水题

class Solution {
public:
    string addSpaces(string s, vector<int>& spaces) {
        int len = s.length();
        string ret = "";
        int i = 0, j = 0;
        while(i < len)
        {
            while(j < spaces.size() && spaces[j] == i)
                ret += ' ', j++;
            ret += s[i++];
        }
        return ret;


        
    }
};

 

posted @ 2022-01-27 09:50  WTSRUVF  阅读(57)  评论(0)    收藏  举报