mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-18 00:57:17 +00:00
Add solution to 'a lot' of problems
This commit is contained in:
23
Easy/shuffle-string/solution.cpp
Normal file
23
Easy/shuffle-string/solution.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
std::string restoreString(std::string s, std::vector<int> &indices) {
|
||||
for (int i = 1; i < indices.size(); i++) {
|
||||
int itmp = indices[i];
|
||||
char ctmp = s[i];
|
||||
int j = i - 1;
|
||||
|
||||
while (j >= 0 && indices[j] > itmp) {
|
||||
indices[j + 1] = indices[j];
|
||||
s[j + 1] = s[j];
|
||||
j = j - 1;
|
||||
}
|
||||
indices[j + 1] = itmp;
|
||||
s[j + 1] = ctmp;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user