Skip to content

Commit 56511fb

Browse files
committed
feat:format code
1 parent a2f3681 commit 56511fb

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
import java.util.ArrayList;
2+
3+
public class Solution {
4+
15
public String[] findWords(String[] words) {
2-
if(words == null){
6+
if (words == null) {
37
return null;
48
}
59
ArrayList<String> list = new ArrayList<>();
6-
String[] keyboards = {"qwertyuiop","asdfghjkl","zxcvbnm"};
10+
String[] keyboards = {"qwertyuiop", "asdfghjkl", "zxcvbnm"};
711
for (int i = 0; i < words.length; i++) {
812
String word = words[i].toLowerCase();
9-
for (int j = 0; j < keyboards.length; j++) {
13+
for (int j = 0; j < keyboards.length; j++) {
1014
// 先用word首字符确定属于哪一行
11-
if(keyboards[j].indexOf(word.charAt(0))>-1){
15+
if (keyboards[j].indexOf(word.charAt(0)) > -1) {
1216
// 判断word字符串所有字符是否都属于同一行
13-
boolean match = match(keyboards[j], word,list);
14-
if(match){
17+
boolean match = match(keyboards[j], word, list);
18+
if (match) {
1519
list.add(words[i]);
1620
}
1721
break;
@@ -22,10 +26,11 @@ public String[] findWords(String[] words) {
2226
}
2327

2428
private boolean match(String keyboard, String word, ArrayList<String> list) {
25-
for (int i = 1; i <word.length() ; i++) {
26-
if(keyboard.indexOf(word.charAt(i))<0){
29+
for (int i = 1; i < word.length(); i++) {
30+
if (keyboard.indexOf(word.charAt(i)) < 0) {
2731
return false;
2832
}
2933
}
30-
return true;
31-
}
34+
return true;
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
int max=0;
2-
int cur=0;
3-
TreeNode preNode = null ;
1+
import java.util.List;
2+
import java.util.ArrayList;
3+
4+
public class Solution {
5+
6+
int max = 0;
7+
int cur = 0;
8+
TreeNode preNode = null;
9+
410
public int[] findMode(TreeNode root) {
511
ArrayList<Integer> list = new ArrayList<>();
612
findMode(root, list);
713
int[] res = new int[list.size()];
8-
for (int i = 0;i<list.size();i++){
14+
for (int i = 0; i < list.size(); i++) {
915
res[i] = list.get(i);
1016
}
1117
return res;
1218
}
1319

1420
private void findMode(TreeNode root, ArrayList<Integer> list) {
15-
if(root == null){
21+
if (root == null) {
1622
return;
1723
}
1824
findMode(root.left, list);
19-
if(preNode!=null && root.val == preNode.val ){
25+
if (preNode != null && root.val == preNode.val) {
2026
cur++;
2127
} else {
2228
cur = 1;
2329
}
24-
if(max < cur ){
30+
if (max < cur) {
2531
max = cur;
2632
list.clear();
2733
list.add(root.val);
28-
}else if(max == cur) {
34+
} else if (max == cur) {
2935
list.add(root.val);
3036
}
3137
preNode = root;
3238
findMode(root.right, list);
3339
}
40+
}

0 commit comments

Comments
 (0)