File tree 2 files changed +7
-1
lines changed
2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change 5
5
import java .util .ArrayList ;
6
6
import java .util .List ;
7
7
8
+ @ SuppressWarnings ("java:S135" )
8
9
public class Solution {
9
10
public List <String > removeComments (String [] source ) {
10
11
List <String > result = new ArrayList <>();
Original file line number Diff line number Diff line change 9
9
import java .util .Map ;
10
10
import java .util .Stack ;
11
11
12
+ @ SuppressWarnings ({"java:S135" , "java:S1149" })
12
13
public class Solution {
13
14
private boolean isLower (char c ) {
14
15
return c >= 97 && c <= 122 ;
@@ -22,10 +23,12 @@ public String countOfAtoms(String formula) {
22
23
int product = 1 ;
23
24
Stack <Integer > mlrStack = new Stack <>();
24
25
Map <String , Integer > count = new HashMap <>();
25
- for (int i = formula .length () - 1 ; i >= 0 ; --i ) {
26
+ int i = formula .length () - 1 ;
27
+ while (i >= 0 ) {
26
28
char c = formula .charAt (i );
27
29
if (c == '(' ) {
28
30
product /= mlrStack .pop ();
31
+ i --;
29
32
continue ;
30
33
}
31
34
int rank = 1 ;
@@ -41,6 +44,7 @@ public String countOfAtoms(String formula) {
41
44
mlrStack .push (mlr );
42
45
product *= mlr ;
43
46
if (c == ')' ) {
47
+ i --;
44
48
continue ;
45
49
}
46
50
StringBuilder atom = new StringBuilder ();
@@ -52,6 +56,7 @@ public String countOfAtoms(String formula) {
52
56
String name = atom .toString ();
53
57
count .put (name , count .getOrDefault (name , 0 ) + product );
54
58
product /= mlrStack .pop ();
59
+ i --;
55
60
}
56
61
List <String > atomList = new ArrayList <>(count .keySet ());
57
62
atomList .sort (Comparator .naturalOrder ());
You can’t perform that action at this time.
0 commit comments