SHARE
TWEET

Untitled

a guest Jun 16th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     string decodeString(string s) {
  4.         stack<int> repeat;
  5.         stack<string> patterns;
  6.         string res;
  7.         int i = 0;
  8.         while (i < s.length())
  9.         {
  10.           string cur;
  11.           while (i < s.length() && isalpha(s[i]))
  12.           {
  13.             cur += s[i];
  14.           }
  15.           if (i < s.length() && s[i] == β€˜]’) ++i;
  16.          
  17.           if (!repeat.empty()) patterns.push(cur);
  18.           else res += cur;
  19.  
  20.           if (s[i] - β€˜0’ < 9 && s[i] - β€˜0’ >=0)
  21.           {
  22.             int step =  s.find(i, β€˜[’);
  23.             repeat.push(atoi(s.substr(i, step);
  24.             i = step + 1;
  25.           }
  26.         }
  27.     }
  28. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top