Skip to content

Commit 0c9a6f7

Browse files
authored
Fixed sonar warnings.
1 parent 7b76028 commit 0c9a6f7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/g0701_0800/s0722_remove_comments/Solution.java

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8+
@SuppressWarnings("java:S135")
89
public class Solution {
910
public List<String> removeComments(String[] source) {
1011
List<String> result = new ArrayList<>();

src/main/java/g0701_0800/s0726_number_of_atoms/Solution.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Map;
1010
import java.util.Stack;
1111

12+
@SuppressWarnings({"java:S135", "java:S1149"})
1213
public 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());

0 commit comments

Comments
 (0)