Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> findPermutation(string s) {
- stack<int> stk;
- vector<int> res;
- int n=s.length()+1;
- for(int i=1; i<=n; i++){
- stk.push(i);
- if(s[i-1] == 'I'){
- while(!stk.empty()){
- res.push_back(stk.top());
- stk.pop();
- }
- }
- }
- while(!stk.empty()){
- res.push_back(stk.top());
- stk.pop();
- }
- return res;
- }
- };
- ------------------------------------------
- class Solution {
- public:
- vector<int> findPermutation(string s) {
- int i=0,j=1;
- vector<int> ans;
- int n=s.length();
- while(i<=n) {
- int l=0;
- while(i<n && s[i]=='D') {
- l++;
- j++;
- i++;
- }
- j++;
- i++;
- l++;
- int k=j-1;
- while(l--) {
- ans.push_back(k--);
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement