Skip to content

Commit 04175b6

Browse files
authored
Create Construct Smallest Number From DI String.java
1 parent 30f2171 commit 04175b6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public String smallestNumber(String pattern) {
3+
StringBuilder result = new StringBuilder();
4+
Stack<Integer> stack = new Stack<>();
5+
for (int i = 0; i <= pattern.length(); i++) {
6+
stack.push(i + 1);
7+
if (i == pattern.length() || pattern.charAt(i) == 'I') {
8+
while (!stack.isEmpty()) {
9+
result.append(stack.pop());
10+
}
11+
}
12+
}
13+
return result.toString();
14+
}
15+
}

0 commit comments

Comments
 (0)