Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  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. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement