SHARE
TWEET

Untitled

a guest Nov 17th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     vector<int> diStringMatch(string S) {
  4.         int low = 0;
  5.         int high = S.length();
  6.         std::vector<int> out(high+1);
  7.        
  8.         int ii=0;
  9.         for (const auto c:S) {
  10.             if (c=='I')
  11.                 out[ii++]=low++;
  12.             else
  13.                 out[ii++]=high--;
  14.         }
  15.         if (S[ii-1]=='D')
  16.             out[ii]=low;
  17.         else
  18.             out[ii]=high;
  19.         return out;
  20.     }
  21. };
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