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 527c180

Browse filesBrowse files
committed
commit
1 parent 8bd9a6e commit 527c180
Copy full SHA for 527c180

File tree

Expand file treeCollapse file tree

17 files changed

+601
-221
lines changed
Filter options
Expand file treeCollapse file tree

17 files changed

+601
-221
lines changed

‎.idea/modules.xml

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

Copy file name to clipboardExpand all lines: .idea/workspace.xml
+274-221Lines changed: 274 additions & 221 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎[0207][Course Schedule]/[0207][Course Schedule].iml

Copy file name to clipboardExpand all lines: [0207][Course Schedule]/[0207][Course Schedule].iml
+2Lines 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>
+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>
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* @author: wangjunchao(王俊超)
3+
* @time: 2019-07-08 20:52
4+
**/
5+
public class Solution {
6+
7+
}

‎[0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml

Copy file name to clipboardExpand all lines: [0240][Search a 2D Matrix II]/[0240][Search a 2D Matrix II].iml
+2Lines 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>

‎[0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml

Copy file name to clipboardExpand all lines: [0241][Different Ways to Add Parentheses]/[0241][Different Ways to Add Parentheses].iml
+2Lines 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>

‎[0292][Nim Game]/[0292][Nim Game].iml

Copy file name to clipboard
+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>

‎[0292][Nim Game]/src/Solution.java

Copy file name to clipboard
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* https://leetcode.com/problems/nim-game/
3+
* @author: wangjunchao(王俊超)
4+
* @time: 2019-07-08 18:39
5+
**/
6+
public class Solution {
7+
/**
8+
* <pre>
9+
* You are playing the following Nim Game with your friend: There is a heap of stones on the table,
10+
* each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will
11+
* be the winner. You will take the first turn to remove the stones.
12+
*
13+
* Both of you are very clever and have optimal strategies for the game. Write a function to determine
14+
* whether you can win the game given the number of stones in the heap.
15+
*
16+
* Example:
17+
*
18+
* Input: 4
19+
* Output: false
20+
* Explanation: If there are 4 stones in the heap, then you will never win the game;
21+
* No matter 1, 2, or 3 stones you remove, the last stone will always be
22+
* removed by your friend.
23+
*
24+
* 这题往小说可以追溯到小学奥数或者脑筋急转弯的书中,往大说可以深究到博弈论。然而编程在这里并没有卵用,
25+
* 策略在于,因为每个人都取不到4个,假设自己后走,要保证每轮自己和对方取得数量的和是4,这样就能确保每
26+
* 轮完后都有4的倍数个石头被取走。这样,如果我们先走的话,先把n除4的余数个石头拿走,这样不管怎样,到最
27+
* 后都会留4个下来,对方取1个你就取3个,对方取2个你就取2个,就必赢了。
28+
* </pre>
29+
* @param n
30+
* @return
31+
*/
32+
public boolean canWinNim(int n) {
33+
return (n & 0b11) > 0;
34+
}
35+
36+
public boolean canWinNim2(int n) {
37+
return n %4 != 0;
38+
}
39+
}

‎[0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml

Copy file name to clipboardExpand all lines: [0427][Construct Quad Tree]/[0427][Construct Quad Tree].iml
+2Lines 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>
+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://$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+
</component>
21+
</module>
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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-08 20:07
9+
**/
10+
public class Main {
11+
@Test
12+
public void test1() {
13+
Solution solution = new Solution();
14+
Assert.assertEquals(Arrays.asList(0, 6), solution.findAnagrams("cbaebabacd", "abc"));
15+
}
16+
17+
@Test
18+
public void test2() {
19+
Solution solution = new Solution();
20+
Assert.assertEquals(Arrays.asList(0, 1, 2), solution.findAnagrams("abab", "ab"));
21+
}
22+
}
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import java.util.Arrays;
2+
import java.util.HashMap;
3+
import java.util.LinkedList;
4+
import java.util.List;
5+
import java.util.Map;
6+
import java.util.Objects;
7+
8+
/**
9+
* @author: wangjunchao(王俊超)
10+
* @time: 2019-07-08 18:59
11+
**/
12+
public class Solution {
13+
/**
14+
* <pre>
15+
* Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
16+
*
17+
* Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
18+
*
19+
* The order of output does not matter.
20+
*
21+
* Example 1:
22+
*
23+
* Input:
24+
* s: "cbaebabacd" p: "abc"
25+
*
26+
* Output:
27+
* [0, 6]
28+
*
29+
* Explanation:
30+
* The substring with start index = 0 is "cba", which is an anagram of "abc".
31+
* The substring with start index = 6 is "bac", which is an anagram of "abc".
32+
* Example 2:
33+
*
34+
* Input:
35+
* s: "abab" p: "ab"
36+
*
37+
* Output:
38+
* [0, 1, 2]
39+
*
40+
* Explanation:
41+
* The substring with start index = 0 is "ab", which is an anagram of "ab".
42+
* The substring with start index = 1 is "ba", which is an anagram of "ab".
43+
* The substring with start index = 2 is "ab", which is an anagram of "ab".
44+
* </pre>
45+
*
46+
* @param s
47+
* @param p
48+
* @return
49+
*/
50+
public List<Integer> findAnagrams(String s, String p) {
51+
List<Integer> result = new LinkedList<>();
52+
53+
if (s.length() < p.length()) {
54+
return result;
55+
}
56+
57+
int[] pArr = new int[26];
58+
int[] sArr = new int[26];
59+
60+
for (int i = 0; i < p.length(); i++) {
61+
pArr[p.charAt(i) - 'a']++;
62+
}
63+
64+
for (int i = 0; i < p.length(); i++) {
65+
sArr[s.charAt(i) - 'a']++;
66+
}
67+
68+
for (int i = 0; i <= s.length() - p.length(); i++) {
69+
if (i > 0) {
70+
sArr[s.charAt(i - 1) - 'a']--;
71+
sArr[s.charAt(i + p.length() - 1) - 'a']++;
72+
}
73+
74+
if (Arrays.equals(sArr, pArr) ) {
75+
result.add(i);
76+
}
77+
}
78+
79+
return result;
80+
}
81+
}
+118Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import java.util.HashMap;
2+
import java.util.LinkedList;
3+
import java.util.List;
4+
import java.util.Map;
5+
import java.util.Objects;
6+
7+
/**
8+
* @author: wangjunchao(王俊超)
9+
* @time: 2019-07-08 18:59
10+
**/
11+
public class Solution2 {
12+
/**
13+
* <pre>
14+
* Given a string s and a non-empty string p, find all the start indices of p's anagrams in s.
15+
*
16+
* Strings consists of lowercase English letters only and the length of both strings s and p will not be larger than 20,100.
17+
*
18+
* The order of output does not matter.
19+
*
20+
* Example 1:
21+
*
22+
* Input:
23+
* s: "cbaebabacd" p: "abc"
24+
*
25+
* Output:
26+
* [0, 6]
27+
*
28+
* Explanation:
29+
* The substring with start index = 0 is "cba", which is an anagram of "abc".
30+
* The substring with start index = 6 is "bac", which is an anagram of "abc".
31+
* Example 2:
32+
*
33+
* Input:
34+
* s: "abab" p: "ab"
35+
*
36+
* Output:
37+
* [0, 1, 2]
38+
*
39+
* Explanation:
40+
* The substring with start index = 0 is "ab", which is an anagram of "ab".
41+
* The substring with start index = 1 is "ba", which is an anagram of "ab".
42+
* The substring with start index = 2 is "ab", which is an anagram of "ab".
43+
* </pre>
44+
*
45+
* @param s
46+
* @param p
47+
* @return
48+
*/
49+
public List<Integer> findAnagrams(String s, String p) {
50+
List<Integer> result = new LinkedList<>();
51+
52+
if (s.length() < p.length()) {
53+
return result;
54+
}
55+
56+
Map<Character, Integer> map1 = getMap(p);
57+
Map<Character, Integer> map2 = getMap(s.substring(0, p.length()));
58+
for (int i = 0; i <= s.length() - p.length(); i++) {
59+
60+
char lastChar = s.charAt(i + p.length() - 1);
61+
char prevChar;
62+
if (i > 0 && (prevChar = s.charAt(i - 1)) != lastChar) {
63+
Integer val = map2.get(prevChar);
64+
if (val <= 1) {
65+
map2.remove(prevChar);
66+
} else {
67+
map2.put(prevChar, val - 1);
68+
}
69+
70+
val = map2.get(lastChar);
71+
if (val == null) {
72+
map2.put(lastChar, 1);
73+
} else {
74+
map2.put(lastChar, val + 1);
75+
}
76+
}
77+
78+
if (equals(map1, map2)) {
79+
result.add(i);
80+
}
81+
}
82+
return result;
83+
}
84+
85+
private boolean equals(Map<Character, Integer> map1, Map<Character, Integer> map2) {
86+
if (map1.size() == map2.size()) {
87+
return contains(map1, map2) && contains(map2, map1);
88+
}
89+
return false;
90+
}
91+
92+
/**
93+
* map1是否包含map2,即map2中的(k, v)都在map1中
94+
*
95+
* @param map1
96+
* @param map2
97+
* @return
98+
*/
99+
private boolean contains(Map<Character, Integer> map1, Map<Character, Integer> map2) {
100+
for (Map.Entry<Character, Integer> e : map2.entrySet()) {
101+
Integer v2 = map1.get(e.getKey());
102+
if (!map1.containsKey(e.getKey()) || !Objects.equals(e.getValue(), v2)) {
103+
return false;
104+
}
105+
}
106+
return true;
107+
}
108+
109+
110+
public Map<Character, Integer> getMap(String s) {
111+
Map<Character, Integer> map = new HashMap<>();
112+
113+
for (int i = 0; i < s.length(); i++) {
114+
map.merge(s.charAt(i), 1, Integer::sum);
115+
}
116+
return map;
117+
}
118+
}

‎[0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml

Copy file name to clipboardExpand all lines: [0485][Max Consecutive Ones]/[0485][Max Consecutive Ones].iml
+2Lines 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>

‎[0496][Next Greater Element I]/[0496][Next Greater Element I].iml

Copy file name to clipboardExpand all lines: [0496][Next Greater Element I]/[0496][Next Greater Element I].iml
+2Lines 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>

0 commit comments

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