Skip to content

Commit 468285f

Browse files
committed
commit
Change-Id: Iab81390de180fb722126be2d4520939693d4c78a
1 parent 4683e29 commit 468285f

File tree

20 files changed

+637
-158
lines changed

20 files changed

+637
-158
lines changed

.idea/modules.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 106 additions & 158 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../lib/junit-4.12.jar!/" />
14+
<root url="jar://$MODULE_DIR$/../lib/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-07-02 08:05
4+
* CSDN: http://blog.csdn.net/derrantcm
5+
* Github: https://github.com/Wang-Jun-Chao
6+
* Declaration: All Rights Reserved !!!
7+
**/
8+
public class Solution {
9+
public boolean checkRecord(String s) {
10+
int a = 0;
11+
int l = 0;
12+
int preLIndex = -1;
13+
if (s != null) {
14+
for (int i = 0; i < s.length(); i++) {
15+
switch (s.charAt(i)) {
16+
case 'A':
17+
a++;
18+
break;
19+
case 'L':
20+
if (l < 3) { // 连续两个L后面步不用记录了
21+
if (preLIndex == -1) { // 刚开始记录
22+
preLIndex = i;
23+
l = 1;
24+
} else if (preLIndex + 1 == i) { // 当前和前一个都是L
25+
l++;
26+
preLIndex = i;
27+
} else { // 前一个不是L,重新记数
28+
preLIndex = i;
29+
l = 1;
30+
}
31+
}
32+
break;
33+
default:
34+
// do nothing
35+
}
36+
}
37+
}
38+
39+
return a <= 1 && l < 3;
40+
}
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
5+
/**
6+
* Author: 王俊超
7+
* Time: 2020-07-02 08:12
8+
* CSDN: http://blog.csdn.net/derrantcm
9+
* Github: https://github.com/Wang-Jun-Chao
10+
* Declaration: All Rights Reserved !!!
11+
**/
12+
public class SolutionTest {
13+
14+
@Test
15+
public void checkRecord() {
16+
Solution s = new Solution();
17+
Object[][] data = {
18+
{"PPALLP", true},
19+
{"PPALLL", false},
20+
};
21+
22+
for (Object[] d : data) {
23+
Assert.assertEquals(d[1], s.checkRecord((String) d[0]));
24+
}
25+
}
26+
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../lib/junit-4.12.jar!/" />
14+
<root url="jar://$MODULE_DIR$/../lib/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.List;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-07-02 07:58
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Node {
11+
public int val;
12+
public List<Node> children;
13+
14+
public Node() {
15+
}
16+
17+
public Node(int val) {
18+
this.val = val;
19+
}
20+
21+
public Node(int val, List<Node> children) {
22+
this.val = val;
23+
this.children = children;
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-07-02 07:58
4+
* CSDN: http://blog.csdn.net/derrantcm
5+
* Github: https://github.com/Wang-Jun-Chao
6+
* Declaration: All Rights Reserved !!!
7+
**/
8+
public class Solution {
9+
public int maxDepth(Node root) {
10+
if (root == null) {
11+
return 0;
12+
}
13+
14+
if (root.children == null || root.children.isEmpty()) {
15+
return 1;
16+
}
17+
18+
int max = 0;
19+
20+
for (Node child : root.children) {
21+
max = Math.max(max, maxDepth(child));
22+
}
23+
24+
return 1 + max;
25+
}
26+
}
27+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import org.junit.Assert;
2+
3+
import java.util.ArrayList;
4+
5+
import static org.junit.Assert.*;
6+
7+
/**
8+
* Author: 王俊超
9+
* Time: 2020-07-02 08:00
10+
* CSDN: http://blog.csdn.net/derrantcm
11+
* Github: https://github.com/Wang-Jun-Chao
12+
* Declaration: All Rights Reserved !!!
13+
**/
14+
public class SolutionTest {
15+
16+
@org.junit.Test
17+
public void maxDepth() {
18+
Node root = new Node(1);
19+
root.children = new ArrayList<>();
20+
root.children.add(new Node(3));
21+
root.children.add(new Node(2));
22+
root.children.add(new Node(4));
23+
root.children.get(0).children = new ArrayList<>();
24+
root.children.get(0).children.add(new Node(5));
25+
root.children.get(0).children.add(new Node(6));
26+
27+
Solution s =new Solution();
28+
29+
Assert.assertEquals(3, s.maxDepth(root));
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../lib/junit-4.12.jar!/" />
14+
<root url="jar://$MODULE_DIR$/../lib/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>

0 commit comments

Comments
 (0)