Leetcode 199场周赛 A题 重新排列字符串

题目链接:https://leetcode-cn.com/contest/weekly-contest-199/problems/shuffle-string/

 

题意描述:

给出一个字符串 以及每个字符对应的位置,求出正确排列之后的字符串。

不知道其他dalao的想法是怎么样的,我就直接对indices数组进行遍历,声明一个新的string来存储。

下面给出代码:

class Solution {
public:
  string restoreString(string s, vector<int>& indices) {
    string a = s;
    for(int i = 0;i < indices.size(); i++){
      a[indices[i]] = s[i];
    }
    return a;
  }
};

 

posted @ 2020-07-26 11:23  Doublevgp  阅读(48)  评论(0)    收藏  举报

载入天数...载入时分秒...