Skip to content

Commit c81f786

Browse files
committed
新增2题,累积21题
1 parent 6e27f09 commit c81f786

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/com/cjl/leetcode/Question_93.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,54 @@ public class Question_93 {
3636
StringBuilder sb = new StringBuilder();
3737

3838
public List<String> solution1(String s) {
39-
if(s.length() > 12) {
39+
if (s.length() > 12) {
4040
return res;
4141
}
4242
sb.append(s);
43-
backTrack(sb,0,0);
43+
backTrack(sb, 0, 0);
4444
return res;
4545
}
4646

4747
private void backTrack(StringBuilder sb, int start, int pointNum) {
4848
// 逗号数量为3时,分隔结束
49-
if(pointNum == 3) {
50-
if(isValid(sb.substring(start,sb.length()))) {
49+
if (pointNum == 3) {
50+
if (isValid(sb.substring(start, sb.length()))) {
5151
res.add(sb.toString());
5252
}
5353
return;
5454
}
5555
for (int i = start; i < sb.length(); i++) {
56-
if(isValid(sb.substring(start,i + 1))) {
56+
if (isValid(sb.substring(start, i + 1))) {
5757
// 在str的后⾯插⼊⼀个逗点
58-
sb.insert(i+1,'.');
58+
sb.insert(i + 1, '.');
5959
// 插入逗号后,下一个子串的起始位置是i+2
6060
backTrack(sb, i + 2, pointNum + 1);
6161
// 回溯删去逗号
6262
sb.deleteCharAt(i + 1);
63-
}else {
63+
} else {
6464
break;
6565
}
6666
}
6767
}
6868

6969
// 判断字符串s在左闭右闭区间[start, end]所组成的数字是否合法
7070
private Boolean isValid(String str) {
71-
if(str == null || str.length() == 0) {
71+
if (str == null || str.length() == 0) {
7272
return false;
7373
}
7474
// 以0为开头的数字不合法
75-
if(str.charAt(0) == '0' && str.length() > 1) {
75+
if (str.charAt(0) == '0' && str.length() > 1) {
7676
return false;
7777
}
7878
int num = 0;
7979
for (int i = 0; i < str.length(); i++) {
8080
// 遇到非数字字符则不合法
81-
if(str.charAt(i) > '9' || str.charAt(i) < '0') {
81+
if (str.charAt(i) > '9' || str.charAt(i) < '0') {
8282
return false;
8383
}
8484
num = num * 10 + (str.charAt(i) - '0');
8585
// 大于255则不合法
86-
if(num > 255) {
86+
if (num > 255) {
8787
return false;
8888
}
8989
}

0 commit comments

Comments
 (0)