Skip to content

Commit 5c9668f

Browse files
committed
Revert "rearrange the dictionary"
This reverts commit 975a7a1.
1 parent 975a7a1 commit 5c9668f

File tree

349 files changed

+49
-1086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

349 files changed

+49
-1086
lines changed

Java/src/leetcode/solution/DataStruct/Solution.java

-740
This file was deleted.

Java/src/leetcode/solution/stack/DecodeString.java

-273
This file was deleted.

Java/src/leetcode/solution/stack/parentheses/Solution.java

-73
This file was deleted.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package leetcode.solution.stack;
2+
3+
import java.util.Stack;
4+
5+
/**
6+
* 394. Decode String
7+
*/
8+
public class DecodeString {
9+
10+
public static void main(String[] args) {
11+
String s = "3[a]2[bc]";
12+
DecodeString decodeString = new DecodeString();
13+
System.out.println(decodeString.decodeString(s));
14+
// Output: "aaabcbc"
15+
}
16+
17+
public String decodeString(String s) {
18+
Stack<StringBuilder> charStack = new Stack<>();
19+
Stack<Integer> countStack = new Stack<>();
20+
StringBuilder current = new StringBuilder();
21+
22+
int k = 0;
23+
for (int i = 0; i < s.length(); i++) {
24+
char ch = s.charAt(i);
25+
if (Character.isDigit(ch)) {
26+
k = k * 10 + ch - '0';
27+
} else if (Character.isLetter(ch)) {
28+
current.append(ch);
29+
} else if ('[' == ch) {
30+
countStack.push(k);
31+
k = 0;
32+
charStack.push(current);
33+
current = new StringBuilder();
34+
} else if (']' == ch) {
35+
StringBuilder encodeStr = current;
36+
int times = countStack.pop();
37+
StringBuilder existStr = charStack.pop();
38+
for (int j = times; j > 0; j--) {
39+
existStr.append(encodeStr);
40+
}
41+
current = existStr;
42+
}
43+
}
44+
45+
return current.toString();
46+
}
47+
48+
49+
}

0 commit comments

Comments
 (0)