Advertisement
nikunjsoni

484

Jun 29th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     vector<int> findPermutation(string s) {
  4.         stack<int> stk;
  5.         vector<int> res;
  6.         int n=s.length()+1;
  7.         for(int i=1; i<=n; i++){
  8.             stk.push(i);
  9.             if(s[i-1] == 'I'){
  10.                 while(!stk.empty()){
  11.                     res.push_back(stk.top());
  12.                     stk.pop();
  13.                 }
  14.             }
  15.         }
  16.         while(!stk.empty()){
  17.             res.push_back(stk.top());
  18.             stk.pop();
  19.         }
  20.         return res;
  21.     }
  22. };
  23.  
  24. ------------------------------------------
  25.  
  26. class Solution {
  27. public:
  28.     vector<int> findPermutation(string s) {
  29.         int i=0,j=1;
  30.         vector<int> ans;
  31.         int n=s.length();
  32.         while(i<=n) {
  33.             int l=0;
  34.             while(i<n && s[i]=='D') {
  35.                 l++;
  36.                 j++;
  37.                 i++;
  38.             }
  39.             j++;
  40.             i++;
  41.             l++;
  42.             int k=j-1;
  43.             while(l--) {
  44.                 ans.push_back(k--);
  45.             }
  46.         }
  47.         return ans;
  48.     }
  49. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement