Untitled
unknown
plain_text
10 months ago
574 B
7
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