File tree Expand file tree Collapse file tree 1 file changed +29
-30
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +29
-30
lines changed Original file line number Diff line number Diff line change 21
21
* Output: ["c","o"]
22
22
*
23
23
* Note:
24
- *
25
24
* 1 <= A.length <= 100
26
25
* 1 <= A[i].length <= 100
27
26
* A[i][j] is a lowercase letter
28
27
*/
29
28
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
+ }
50
57
}
51
- }
52
- if (!valid ) {
53
- break ;
54
- } else {
55
- result .add ("" + c );
56
- }
58
+ return result ;
57
59
}
58
- }
59
- return result ;
60
60
}
61
- }
62
61
}
You can’t perform that action at this time.
0 commit comments