Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d4880a9

Browse files
committed
commit
1 parent def39ad commit d4880a9

File tree

22 files changed

+798
-318
lines changed

22 files changed

+798
-318
lines changed

.idea/modules.xml

Lines changed: 4 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: 394 additions & 318 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

[0227][Basic Calculator II]/[0227][Basic Calculator II].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>

[0228][Summary Ranges]/[0228][Summary Ranges].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
/**
5+
* @author: wangjunchao(王俊超)
6+
* @time: 2019-07-11 13:34
7+
**/
8+
public class Main {
9+
@Test
10+
public void test1() {
11+
char[][] board = {
12+
{'X','.', ',', 'X'},
13+
{'.','.', ',', 'X'},
14+
{'.','.', ',', 'X'}
15+
};
16+
17+
Solution solution = new Solution();
18+
Assert.assertEquals(2, solution.countBattleships(board));
19+
}
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @author: wangjunchao(王俊超)
3+
* @time: 2019-07-11 13:23
4+
**/
5+
public class Solution {
6+
public int countBattleships(char[][] board) {
7+
8+
if (board == null || board.length < 1) {
9+
return 0;
10+
}
11+
12+
int result = 0;
13+
for (int i = 0; i < board.length; i++) {
14+
for (int j = 0; j < board[0].length; j++) {
15+
// 当前位置是X
16+
if (board[i][j] == 'X') {
17+
// 如果左边一个并且上面一个不是X,说明是战舰的起点
18+
// 考虑边界情况
19+
if (i > 0 && j > 0 && board[i -1][j] != board[i][j] && board[i][j - 1] != board[i][j]) {
20+
result++;
21+
} else if (i > 0 && j == 0 && board[i -1][j] != board[i][j]) {
22+
result++;
23+
} else if (i == 0 && j > 0 && board[i][j - 1] != board[i][j] ) {
24+
result++;
25+
} else if (i == 0 && j == 0) {
26+
result++;
27+
}
28+
}
29+
}
30+
}
31+
32+
return result;
33+
}
34+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
import java.util.Arrays;
5+
6+
/**
7+
* @author: wangjunchao(王俊超)
8+
* @time: 2019-07-11 14:08
9+
**/
10+
public class Main {
11+
@Test
12+
public void test1() {
13+
int[] nums = {4, 3, 2, 7, 8, 2, 3, 1};
14+
Solution solution = new Solution();
15+
Assert.assertEquals(Arrays.asList(2, 3), solution.findDuplicates(nums));
16+
}
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.HashSet;
4+
import java.util.LinkedList;
5+
import java.util.List;
6+
import java.util.Set;
7+
8+
/**
9+
* @author: wangjunchao(王俊超)
10+
* @time: 2019-07-11 13:49
11+
**/
12+
public class Solution {
13+
public List<Integer> findDuplicates(int[] nums) {
14+
List<Integer> result = new ArrayList<>();
15+
16+
if (nums == null || nums.length < 1) {
17+
return result;
18+
}
19+
20+
Set<Integer> set = new HashSet<>();
21+
22+
for(int i: nums) {
23+
if (set.contains(i)) {
24+
result.add(i);
25+
} else {
26+
set.add(i);
27+
}
28+
}
29+
30+
Collections.sort(result);
31+
return result;
32+
}
33+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.List;
4+
5+
/**
6+
* @author: wangjunchao(王俊超)
7+
* @time: 2019-07-11 13:49
8+
**/
9+
public class Solution2 {
10+
public List<Integer> findDuplicates(int[] nums) {
11+
List<Integer> result = new ArrayList<>();
12+
13+
if (nums == null || nums.length < 1) {
14+
return result;
15+
}
16+
17+
int idx = 1;
18+
19+
while (idx <= nums.length) {
20+
// 如果nums[9-1] != 9 说明还没有调整到位置
21+
// nums[idx-1] == nums[nums[idx-1] - 1]说明有同样的值出现
22+
while (nums[idx - 1] != idx && nums[idx - 1] != nums[nums[idx - 1] - 1]) {
23+
swap(nums, idx - 1, nums[idx - 1] - 1);
24+
}
25+
26+
idx++;
27+
}
28+
29+
for (int i = 1; i <= nums.length; i++) {
30+
if (nums[i - 1] != i) {
31+
result.add(nums[i - 1]);
32+
}
33+
}
34+
35+
Collections.sort(result);
36+
return result;
37+
}
38+
39+
private void swap(int[] nums, int x, int y) {
40+
int temp = nums[x];
41+
nums[x] = nums[y];
42+
nums[y] = temp;
43+
}
44+
}

[0455][Assign Cookies]/[0455][Assign Cookies].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>

[0475][Heaters]/[0475][Heaters].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>

[0482][License Key Formatting]/[0482][License Key Formatting].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>

[0492][Construct the Rectangle]/[0492][Construct the Rectangle].iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@
1717
<SOURCES />
1818
</library>
1919
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
2022
</component>
2123
</module>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>

[0500][Keyboard Row]/src/Main.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import org.junit.Assert;
2+
import org.junit.Test;
3+
4+
/**
5+
* @author: wangjunchao(王俊超)
6+
* @time: 2019-07-11 10:39
7+
**/
8+
public class Main {
9+
@Test
10+
public void test1() {
11+
Solution solution = new Solution();
12+
13+
Assert.assertArrayEquals(new String[]{"Alaska", "Dad"}, solution.findWords(new String[]{"Hello", "Alaska", "Dad", "Peace"}));
14+
}
15+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import java.util.LinkedList;
3+
import java.util.List;
4+
5+
/**
6+
* https://leetcode.com/problems/keyboard-row/
7+
* @author: wangjunchao(王俊超)
8+
* @time: 2019-07-11 10:25
9+
**/
10+
public class Solution {
11+
12+
13+
public String[] findWords(String[] words) {
14+
String[] lines = {
15+
"`1234567890-=~!@#$%^&*()_+",
16+
"qwertyuiop[]\\QWERTYUIOP{}|",
17+
"asdfghjkl;'ASDFGHJKL:\"",
18+
"zxcvbnm,./ZXCVBNM<>?"};
19+
20+
if (words == null || words.length < 1) {
21+
return words;
22+
}
23+
24+
List<String> result = new LinkedList<>();
25+
for (String s : words) {
26+
for (String l : lines) {
27+
if (contains(l, s)) {
28+
result.add(s);
29+
break;
30+
}
31+
}
32+
}
33+
34+
return result.toArray(new String[0]);
35+
}
36+
37+
private boolean contains(String s, String t) {
38+
for (int i = 0; i < t.length(); i++) {
39+
if (s.indexOf(t.charAt(i)) < 0) {
40+
return false;
41+
}
42+
43+
}
44+
return true;
45+
}
46+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
<orderEntry type="library" name="R User Library" level="project" />
21+
<orderEntry type="library" name="R Skeletons" level="application" />
22+
</component>
23+
</module>

0 commit comments

Comments
 (0)