Skip to content

Commit ce53c97

Browse files
committed
commit
Change-Id: Ib8fb3df671488e52b13296e875a02e3473b0473b
1 parent 7a208fa commit ce53c97

File tree

10 files changed

+269
-48
lines changed

10 files changed

+269
-48
lines changed

.idea/modules.xml

Lines changed: 3 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: 53 additions & 48 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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-07-07 10:03
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+
10+
public int findLengthOfLCIS(int[] nums) {
11+
if (nums == null) {
12+
return 0;
13+
} else if (nums.length < 2) {
14+
return nums.length;
15+
}
16+
17+
int prev = 0;
18+
int max = 0;
19+
for (int i = 1; i < nums.length; i++) {
20+
while (i < nums.length && nums[i - 1] < nums[i]) {
21+
i++;
22+
}
23+
24+
max = Math.max(max, i - prev);
25+
prev = i;
26+
}
27+
28+
return max;
29+
}
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import org.junit.Assert;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-07-07 10:07
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class SolutionTest {
11+
12+
@org.junit.Test
13+
public void findLengthOfLCIS() {
14+
Solution s = new Solution();
15+
Object[][] data = {
16+
{new int[]{1, 3, 5, 4, 7}, 3},
17+
{new int[]{2, 2, 2, 2, 2}, 1},
18+
{new int[]{1, 2, 3, 4, 5}, 5},
19+
{new int[]{2, 2, 3, 4, 5}, 4},
20+
};
21+
22+
for (Object[] d : data) {
23+
int result = s.findLengthOfLCIS((int[]) d[0]);
24+
Assert.assertEquals(d[1], result);
25+
}
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
</component>
11+
</module>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-07-07 10:12
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 validPalindrome(String s) {
10+
int start = 0;
11+
int end = s.length() - 1;
12+
while (start < end) {
13+
// 有一个不相等,可以抛弃start或者end字符,抛弃一个字符后,后面的都要是回文
14+
if (s.charAt(start) != s.charAt(end)) {
15+
return validPalindrome(s, start + 1, end) || validPalindrome(s, start, end - 1);
16+
}
17+
start++;
18+
end--;
19+
}
20+
21+
return true;
22+
}
23+
24+
private boolean validPalindrome(String s, int start, int end) {
25+
while (start < end) {
26+
if (s.charAt(start) != s.charAt(end)) {
27+
return false;
28+
}
29+
start++;
30+
end--;
31+
}
32+
33+
return true;
34+
}
35+
}
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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.util.LinkedList;
2+
import java.util.List;
3+
4+
/**
5+
* Author: 王俊超
6+
* Time: 2020-07-07 12:46
7+
* CSDN: http://blog.csdn.net/derrantcm
8+
* Github: https://github.com/Wang-Jun-Chao
9+
* Declaration: All Rights Reserved !!!
10+
**/
11+
public class Solution {
12+
public int calPoints(String[] ops) {
13+
14+
if (ops == null || ops.length < 1) {
15+
return 0;
16+
}
17+
List<Integer> round = new LinkedList<>();
18+
19+
for (String o : ops) {
20+
int size = round.size();
21+
switch (o) {
22+
case "+":
23+
round.add(round.get(size - 1) + round.get(size - 2));
24+
break;
25+
case "D":
26+
round.add(2 * round.get(size - 1));
27+
break;
28+
case "C":
29+
round.remove(size - 1);
30+
break;
31+
default:
32+
round.add(Integer.parseInt(o));
33+
}
34+
}
35+
36+
int sum = 0;
37+
for(Integer n : round) {
38+
sum += n;
39+
}
40+
41+
return sum;
42+
}
43+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import org.junit.Assert;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-07-07 12:53
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class SolutionTest {
11+
12+
@org.junit.Test
13+
public void calPoints() {
14+
Solution s = new Solution();
15+
Object[][] data = {
16+
{new String[]{"5", "2", "C", "D", "+"}, 30},
17+
{new String[]{"5", "-2", "4", "C", "D", "9", "+", "+"}, 27},
18+
};
19+
20+
for (Object[] d : data) {
21+
int result = s.calPoints((String[]) d[0]);
22+
Assert.assertEquals(d[1], result);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)