Skip to content

Commit d0747cc

Browse files
committed
commit
Change-Id: I063540e070f881de78b6f278119ce7a7e05f8e75
1 parent c07b459 commit d0747cc

File tree

19 files changed

+644
-136
lines changed

19 files changed

+644
-136
lines changed

.idea/modules.xml

Lines changed: 6 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: 120 additions & 136 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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 08:33
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 checkPerfectNumber(int num) {
10+
if (num < 6) {
11+
return false;
12+
}
13+
14+
int sum = 1;
15+
int sqrt = (int) Math.sqrt(num);
16+
17+
for (int i = 2; i <= sqrt; i++) {
18+
if (num % i == 0) {
19+
sum += i;
20+
sum += num / i;
21+
}
22+
}
23+
24+
return sum == num;
25+
}
26+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import org.junit.Assert;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-29 08:36
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 checkPerfectNumber() {
14+
Solution s = new Solution();
15+
Object[][] data = {
16+
{28, true},
17+
{-1, false},
18+
{0, false},
19+
{1, false},
20+
{6, true},
21+
{7, false},
22+
{8, false},
23+
};
24+
25+
for (Object[] d: data) {
26+
Assert.assertEquals(s.checkPerfectNumber((Integer) d[0]), d[1]);
27+
}
28+
}
29+
}
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 08:44
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 fib(int N) {
10+
if (N <= 0) {
11+
return 0;
12+
} else if (N == 1) {
13+
return 1;
14+
}
15+
16+
int n2 = 0;
17+
int n1 = 1;
18+
int n0;
19+
for (int i = 2; i <= N; i++) {
20+
n0 = n1 + n2;
21+
n2 = n1;
22+
n1 = n0;
23+
}
24+
25+
return n1;
26+
}
27+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import org.junit.Assert;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-29 08:48
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 fib() {
14+
Solution s = new Solution();
15+
Object[][] data = {
16+
{0, 0},
17+
{1, 1},
18+
{2, 1},
19+
{3, 2},
20+
};
21+
22+
for (Object[] d : data) {
23+
Assert.assertEquals(s.fib((Integer) d[0]), d[1]);
24+
}
25+
}
26+
}
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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 08:42
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+
* <pre>
11+
* Given a word, you need to judge whether the usage of capitals in it is right or not.
12+
*
13+
* We define the usage of capitals in a word to be right when one of the following
14+
* cases holds:
15+
*
16+
* All letters in this word are capitals, like "USA".
17+
* All letters in this word are not capitals, like "leetcode".
18+
* Only the first letter in this word is capital, like "Google".
19+
* Otherwise, we define that this word doesn't use capitals in a right way.
20+
*
21+
*
22+
* Example 1:
23+
*
24+
* Input: "USA"
25+
* Output: True
26+
*
27+
*
28+
* Example 2:
29+
*
30+
* Input: "FlaG"
31+
* Output: False
32+
*
33+
*
34+
* Note: The input will be a non-empty word consisting of uppercase
35+
* and lowercase latin letters.
36+
* </pre>
37+
*
38+
* @param word
39+
* @return
40+
*/
41+
public boolean detectCapitalUse(String word) {
42+
43+
if (Character.isUpperCase(word.charAt(0))) {
44+
return isAllUpperCase(word.substring(1)) || isAllLowerCase(word.substring(1));
45+
} else if (Character.isLowerCase(word.charAt(0))) {
46+
return isAllLowerCase(word.substring(1));
47+
}
48+
49+
return false;
50+
}
51+
52+
private boolean isAllLowerCase(String s) {
53+
for (int i = 0; i < s.length(); i++) {
54+
if (!Character.isLowerCase(s.charAt(i))) {
55+
return false;
56+
}
57+
}
58+
59+
return true;
60+
}
61+
62+
private boolean isAllUpperCase(String s) {
63+
64+
for (int i = 0; i < s.length(); i++) {
65+
if (!Character.isUpperCase(s.charAt(i))) {
66+
return false;
67+
}
68+
}
69+
70+
return true;
71+
}
72+
}
73+

0 commit comments

Comments
 (0)