File tree Expand file tree Collapse file tree 2 files changed +7
-1
lines changed
Expand file tree Collapse file tree 2 files changed +7
-1
lines changed Original file line number Diff line number Diff line change 55import java .util .ArrayList ;
66import java .util .List ;
77
8+ @ SuppressWarnings ("java:S135" )
89public class Solution {
910 public List <String > removeComments (String [] source ) {
1011 List <String > result = new ArrayList <>();
Original file line number Diff line number Diff line change 99import java .util .Map ;
1010import java .util .Stack ;
1111
12+ @ SuppressWarnings ({"java:S135" , "java:S1149" })
1213public class Solution {
1314 private boolean isLower (char c ) {
1415 return c >= 97 && c <= 122 ;
@@ -22,10 +23,12 @@ public String countOfAtoms(String formula) {
2223 int product = 1 ;
2324 Stack <Integer > mlrStack = new Stack <>();
2425 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 ) {
2628 char c = formula .charAt (i );
2729 if (c == '(' ) {
2830 product /= mlrStack .pop ();
31+ i --;
2932 continue ;
3033 }
3134 int rank = 1 ;
@@ -41,6 +44,7 @@ public String countOfAtoms(String formula) {
4144 mlrStack .push (mlr );
4245 product *= mlr ;
4346 if (c == ')' ) {
47+ i --;
4448 continue ;
4549 }
4650 StringBuilder atom = new StringBuilder ();
@@ -52,6 +56,7 @@ public String countOfAtoms(String formula) {
5256 String name = atom .toString ();
5357 count .put (name , count .getOrDefault (name , 0 ) + product );
5458 product /= mlrStack .pop ();
59+ i --;
5560 }
5661 List <String > atomList = new ArrayList <>(count .keySet ());
5762 atomList .sort (Comparator .naturalOrder ());
You can’t perform that action at this time.
0 commit comments