Skip to content

Commit d0a20b8

Browse files
committed
[Function add]
1. Add leetcode solutions.
1 parent 8068731 commit d0a20b8

File tree

7 files changed

+131
-0
lines changed

7 files changed

+131
-0
lines changed

Algorithm(4th_Edition)/.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Algorithm(4th_Edition)/.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Algorithm(4th_Edition)/.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Algorithm(4th_Edition)/.idea/workspace.xml

+65
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="EclipseModuleManager">
4+
<libelement value="jar://$MODULE_DIR$/lib/algs4.jar!/" />
5+
<src_description expected_position="0">
6+
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
7+
</src_description>
8+
</component>
9+
<component name="NewModuleRootManager">
10+
<output url="file://$MODULE_DIR$/bin" />
11+
<exclude-output />
12+
<content url="file://$MODULE_DIR$">
13+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
14+
</content>
15+
<orderEntry type="sourceFolder" forTests="false" />
16+
<orderEntry type="jdk" jdkName="jre" jdkType="JavaSDK" />
17+
<orderEntry type="module-library">
18+
<library name="algs4.jar">
19+
<CLASSES>
20+
<root url="jar://$MODULE_DIR$/lib/algs4.jar!/" />
21+
</CLASSES>
22+
<JAVADOC />
23+
<SOURCES />
24+
</library>
25+
</orderEntry>
26+
</component>
27+
</module>

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@
381381

382382
[217. Contains Duplicate](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/217.%20Contains%20Duplicate.md)
383383

384+
[219. Contains Duplicate II](https://github.com/Seanforfun/Algorithm-and-Leetcode/blob/master/leetcode/219.%20Contains%20Duplicate%20II.md)
385+
384386
## Algorithm(4th_Edition)
385387
Reading notes of book Algorithm(4th Algorithm),ISBN: 9787115293800.
386388
All java realization codes are placed in different packages.

leetcode/219. Contains Duplicate II.md

+17
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,21 @@ class Solution {
3939
return false;
4040
}
4141
}
42+
```
43+
44+
### 二刷
45+
```Java
46+
class Solution {
47+
public boolean containsNearbyDuplicate(int[] nums, int k) {
48+
Map<Integer, Integer> map = new HashMap<>();
49+
for(int i = 0; i < nums.length; i++){
50+
int cur = nums[i];
51+
if(map.containsKey(cur)){
52+
if(i - map.get(cur) <= k) return true;
53+
}
54+
map.put(cur, i);
55+
}
56+
return false;
57+
}
58+
}
4259
```

0 commit comments

Comments
 (0)