Skip to content

Commit 4682f28

Browse files
refactor 385
1 parent d185bd7 commit 4682f28

File tree

1 file changed

+3
-33
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-33
lines changed

src/main/java/com/fishercoder/solutions/_385.java

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,6 @@
44

55
import java.util.Stack;
66

7-
/**
8-
* 385. Mini Parser
9-
*
10-
* Given a nested list of integers represented as a string,
11-
* implement a parser to deserialize it.
12-
13-
Each element is either an integer, or a list --
14-
whose elements may also be integers or other lists.
15-
16-
Note: You may assume that the string is well-formed:
17-
18-
String is non-empty.
19-
String does not contain white spaces.
20-
String contains only digits 0-9, [, - ,, ].
21-
Example 1:
22-
23-
Given s = "324",
24-
25-
You should return a NestedInteger object which contains a single integer 324.
26-
Example 2:
27-
28-
Given s = "[123,[456,[789]]]",
29-
30-
Return a NestedInteger object containing a nested list with 2 elements:
31-
32-
1. An integer containing value 123.
33-
2. A nested list containing two elements:
34-
i. An integer containing value 456.
35-
ii. A nested list with one element:
36-
a. An integer containing value 789.*/
377
public class _385 {
388

399
public static class Solution1 {
@@ -58,7 +28,7 @@ public NestedInteger deserialize(String s) {
5828
if (s.charAt(i) != '[') {
5929
sb.setLength(0);
6030
while (i < s.length() && ((Character.getNumericValue(s.charAt(i)) < 10
61-
&& Character.getNumericValue(s.charAt(i)) >= 0) || s.charAt(i) == '-')) {
31+
&& Character.getNumericValue(s.charAt(i)) >= 0) || s.charAt(i) == '-')) {
6232
sb.append(s.charAt(i));
6333
i++;
6434
}
@@ -87,8 +57,8 @@ public NestedInteger deserialize(String s) {
8757
// then it must be a number
8858
sb.setLength(0);
8959
while (i < s.length()
90-
&& ((Character.getNumericValue(s.charAt(i)) < 10 && Character
91-
.getNumericValue(s.charAt(i)) >= 0) || s.charAt(i) == '-')) {
60+
&& ((Character.getNumericValue(s.charAt(i)) < 10 && Character
61+
.getNumericValue(s.charAt(i)) >= 0) || s.charAt(i) == '-')) {
9262
sb.append(s.charAt(i));
9363
i++;
9464
}

0 commit comments

Comments
 (0)