Untitled

 avatar
unknown
plain_text
2 months ago
574 B
4
Indexable
class Solution {
public:
    string smallestNumber(string pattern) {
        stack < int > st;
        string result = "";

        for(int i=0;i<pattern.size();i++) {
            st.push(i+1);

            if(pattern[i] == 'I') {
                while(!st.empty()) {
                    result+=st.top() + '0';
                    st.pop();
                }
            }
        }

        int sz = pattern.size();

        st.push(sz + 1);

        while(!st.empty()) {
            result+=st.top() + '0';
            st.pop();
        }

        return result;
    }
};
Editor is loading...
Leave a Comment