Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 694a277

Browse files
Time: 339 ms (9.71%), Space: 32.3 MB (90.3%) - LeetHub
1 parent c26f1dc commit 694a277

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
string robotWithString(string s) {
4+
vector<int> f(26);
5+
for (auto& i : s) f[i - 'a']++;
6+
stack<char> stk;
7+
string ans;
8+
for (auto& i : s) {
9+
f[i - 'a']--;
10+
stk.push(i);
11+
while (!stk.empty()) {
12+
bool ok = true;
13+
for (int j = 0; j < stk.top() - 'a'; j++) {
14+
if (f[j]) ok = false;
15+
}
16+
if (!ok) break;
17+
ans += stk.top();
18+
stk.pop();
19+
}
20+
}
21+
return ans;
22+
}
23+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /