Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d0747cc

Browse filesBrowse files
committed
commit
Change-Id: I063540e070f881de78b6f278119ce7a7e05f8e75
1 parent c07b459 commit d0747cc
Copy full SHA for d0747cc

File tree

Expand file treeCollapse file tree

19 files changed

+644
-136
lines changed
Filter options
Expand file treeCollapse file tree

19 files changed

+644
-136
lines changed

‎.idea/modules.xml

Copy file name to clipboardExpand all lines: .idea/modules.xml
+6Lines 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

Copy file name to clipboardExpand all lines: .idea/workspace.xml
+120-136Lines changed: 120 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+21Lines 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>
+26Lines 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+
}
+29Lines 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+
}
+21Lines 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>
+27Lines 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+
}
+26Lines 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+
}
+11Lines 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>
+73Lines 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+
+11Lines 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>
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 08:55
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+
* @param a
11+
* @param b
12+
* @return
13+
*/
14+
public int findLUSlength(String a, String b) {
15+
if (a.equals(b)) {
16+
return -1;
17+
}
18+
return Math.max(a.length(), b.length());
19+
}
20+
}
+21Lines 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>
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-30 08:52
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Solution {
11+
public int findPairs(int[] nums, int k) {
12+
if (nums == null || nums.length < 2 || k < 0) {
13+
return 0;
14+
}
15+
16+
int result = 0;
17+
18+
Arrays.sort(nums);
19+
20+
for (int i = 0; i < nums.length - 1;i++) {
21+
22+
for (int j = i + 1; j < nums.length && nums[j] - nums[i] <= k; j++) {
23+
while (j + 1 < nums.length && nums[j] == nums[j + 1]) {
24+
j++;
25+
}
26+
27+
if (nums[j] - nums[i] == k) {
28+
result++;
29+
}
30+
}
31+
32+
while (i + 1 < nums.length && nums[i] == nums[i + 1]) {
33+
i++;
34+
}
35+
36+
}
37+
38+
return result;
39+
}
40+
}
+27Lines 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-06-30 08:56
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 findPairs() {
14+
Solution s = new Solution();
15+
Object[][] data = {
16+
{new int[]{3, 1, 4, 1, 5}, 2, 2},
17+
{new int[]{1, 2, 3, 4, 5}, 1, 4},
18+
{new int[]{1, 3, 1, 5, 4}, 0, 1},
19+
{new int[]{1, 1, 1, 1, 1}, 0, 1},
20+
{new int[]{1, 1, 2, 2, 1}, 0, 2},
21+
};
22+
23+
for (Object[] d: data) {
24+
Assert.assertEquals(d[2], s.findPairs((int[]) d[0], (Integer) d[1]));
25+
}
26+
}
27+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.