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 ba1f31c

Browse files
Create Process String with Special Operations I.java
1 parent 56dc31b commit ba1f31c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public String processStr(String s) {
3+
StringBuilder sb = new StringBuilder();
4+
for (char c : s.toCharArray()) {
5+
switch (c) {
6+
case '*' -> {
7+
if (!sb.isEmpty()) {
8+
sb.deleteCharAt(sb.length() - 1);
9+
}
10+
}
11+
case '#' -> {
12+
if (!sb.isEmpty()) {
13+
sb.append(sb);
14+
}
15+
}
16+
case '%' -> sb.reverse();
17+
default -> sb.append(c);
18+
}
19+
}
20+
return sb.toString();
21+
}
22+
}

0 commit comments

Comments
(0)

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