Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 28b1725

Browse files
refactor 1002
1 parent 204f5a0 commit 28b1725

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,41 @@
2121
* Output: ["c","o"]
2222
*
2323
* Note:
24-
*
2524
* 1 <= A.length <= 100
2625
* 1 <= A[i].length <= 100
2726
* A[i][j] is a lowercase letter
2827
*/
2928
public class _1002 {
30-
public static class Solution1 {
31-
public List<String> commonChars(String[] A) {
32-
int[][] charCount = new int[A.length][26];
33-
for (int i = 0; i < A.length; i++) {
34-
for (char c : A[i].toCharArray()) {
35-
charCount[i][c - 'a']++;
36-
}
37-
}
38-
List<String> result = new ArrayList<>();
39-
for (int i = 0; i < 26; i++) {
40-
while (charCount[0][i] != 0) {
41-
char c = (char) (i + 'a');
42-
boolean valid = true;
43-
charCount[0][i]--;
44-
for (int j = 1; j < A.length; j++) {
45-
if (charCount[j][i] == 0) {
46-
valid = false;
47-
break;
48-
} else {
49-
charCount[j][i]--;
29+
public static class Solution1 {
30+
public List<String> commonChars(String[] A) {
31+
int[][] charCount = new int[A.length][26];
32+
for (int i = 0; i < A.length; i++) {
33+
for (char c : A[i].toCharArray()) {
34+
charCount[i][c - 'a']++;
35+
}
36+
}
37+
List<String> result = new ArrayList<>();
38+
for (int i = 0; i < 26; i++) {
39+
while (charCount[0][i] != 0) {
40+
char c = (char) (i + 'a');
41+
boolean valid = true;
42+
charCount[0][i]--;
43+
for (int j = 1; j < A.length; j++) {
44+
if (charCount[j][i] == 0) {
45+
valid = false;
46+
break;
47+
} else {
48+
charCount[j][i]--;
49+
}
50+
}
51+
if (!valid) {
52+
break;
53+
} else {
54+
result.add("" + c);
55+
}
56+
}
5057
}
51-
}
52-
if (!valid) {
53-
break;
54-
} else {
55-
result.add("" + c);
56-
}
58+
return result;
5759
}
58-
}
59-
return result;
6060
}
61-
}
6261
}

0 commit comments

Comments
 (0)