Skip to content

Commit e491d82

Browse files
updating all READMEs
1 parent 62ad6fd commit e491d82

File tree

7 files changed

+177
-7
lines changed

7 files changed

+177
-7
lines changed

.dev/logs.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@
367367
"78": {
368368
"len": 3,
369369
"sols": {
370-
"subsets.go": "66eb0c49d04f65acef9efa62171e962f0786eb65d3f25363951db134d3161d8a"
370+
"subsets.go": "66eb0c49d04f65acef9efa62171e962f0786eb65d3f25363951db134d3161d8a",
371+
"subsets.py": "63e9c03df2b03190e4f472fbbfc391dc73cfa495a46a29cee6faf9ca448882da"
371372
}
372373
},
373374
"79": {
@@ -985,16 +986,20 @@
985986
"sols": {}
986987
},
987988
"217": {
988-
"len": 0,
989-
"sols": {}
989+
"len": 2,
990+
"sols": {
991+
"contains_duplicate.rs": "a930019d06bc3dba8b91d087241b0f3324f142e2238424c4954cc26517cfca81"
992+
}
990993
},
991994
"218": {
992995
"len": 0,
993996
"sols": {}
994997
},
995998
"219": {
996-
"len": 0,
997-
"sols": {}
999+
"len": 2,
1000+
"sols": {
1001+
"contains_duplicate_II.go": "7c4997c7a56c3313bd82b0224160bb65b66e25cb95630bc7f3679ce23bff948b"
1002+
}
9981003
},
9991004
"220": {
10001005
"len": 0,

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
[**_Rejection Sampling_**][rejection sampling]   
9696
[**_Biconnected Component_**][biconnected component]
9797

98-
### **Total Problems Solved: _103_**
98+
### **Total Problems Solved: _105_**
9999

100100
---
101101

TOPICWISE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
| **0136** | [Single Number][136] | Array, Bit Manip | ![][easy] | |
3838
| **0169** | [Majority Element][169] | Array, Hash Table, DNC, Sorting, Counting | ![][easy] | |
3939
| **0200** | [Number of Islands][200] | Array, Depth-First Search, Breadth-First Search, Union Find, Matrix | ![][medium] | |
40+
| **0217** | [Contains Duplicate][217] | Array, Hash Table, Sorting | ![][easy] | |
41+
| **0219** | [Contains Duplicate II][219] | Array, Hash Table, Sliding Window | ![][easy] | |
4042
| **0283** | [Move Zeroes][283] | Array, Two Pointers | ![][easy] | |
4143
| **0300** | [Longest Increasing Subsequence][300] | Array, Binary Search, DP | ![][medium] | |
4244
| **0322** | [Coin Change][322] | Array, DP, BFS | ![][medium] | |
@@ -96,6 +98,8 @@
9698
| **0169** | [Majority Element][169] | Array, Hash Table, DNC, Sorting, Counting | ![][easy] | |
9799
| **0202** | [Happy Number][202] | Hash Table, Math, 2P | ![][easy] | |
98100
| **0205** | [Isomorphic Strings][205] | Hash Table, String | ![][easy] | |
101+
| **0217** | [Contains Duplicate][217] | Array, Hash Table, Sorting | ![][easy] | |
102+
| **0219** | [Contains Duplicate II][219] | Array, Hash Table, Sliding Window | ![][easy] | |
99103
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
100104
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
101105
| **0442** | [Find All Duplicates][442] | Array, Hash Table | ![][medium] | |
@@ -159,6 +163,7 @@
159163
| **0075** | [Sort Colors][75] | Array, Two Pointers, Sorting | ![][medium] | |
160164
| **0088** | [Merge Sorted Array][88] | Array, 2P, Sorting | ![][easy] | |
161165
| **0169** | [Majority Element][169] | Array, Hash Table, DNC, Sorting, Counting | ![][easy] | |
166+
| **0217** | [Contains Duplicate][217] | Array, Hash Table, Sorting | ![][easy] | |
162167
| **0389** | [Find the Difference][389] | Hash Table, String, Bit Manipulation, Sorting | ![][easy] | |
163168
| **0506** | [Relative Ranks][506] | Array, Sorting, Heap | ![][easy] | |
164169
| **0888** | [Fair Candy Swap][888] | Array, Hash Table, Binary Search, Sorting | ![][easy] | |
@@ -417,6 +422,7 @@
417422

418423
| # | Solution | Tags | Difficulty | Remark |
419424
| :------: | :----------------------------------: | :--------------------------------: | :---------: | :----: |
425+
| **0219** | [Contains Duplicate II][219] | Array, Hash Table, Sliding Window | ![][easy] | |
420426
| **0438** | [Find All Anagrams in a String][438] | Hash Table, String, Sliding Window | ![][medium] | |
421427

422428
<!---------------------------------{ Solution Table }-------------------------->
@@ -848,6 +854,8 @@
848854
[203]: ./src/0201-0300/203%20-%20Remove%20Linked%20List%20Elements/
849855
[205]: ./src/0201-0300/205%20-%20Isomorphic%20Strings/
850856
[206]: ./src/0201-0300/206%20-%20Reverse%20Linked%20List/
857+
[217]: ./src/0201-0300/217%20-%20Contains%20Duplicate/
858+
[219]: ./src/0201-0300/219%20-%20Contains%20Duplicate%20II/
851859
[222]: ./src/0201-0300/222%20-%20Count%20Complete%20Tree%20Nodes/
852860
[230]: ./src/0201-0300/230%20-%20Kth%20Smallest%20Element%20in%20a%20BST/
853861
[231]: ./src/0201-0300/231%20-%20Power%20of%20Two/

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ It might take some time to reflect changes from the repository.
103103
[**_Rejection Sampling_**][rejection sampling] &nbsp;&nbsp;
104104
[**_Biconnected Component_**][biconnected component]
105105

106-
### **Total Problems Solved: _103_**
106+
### **Total Problems Solved: _105_**
107107

108108
## Contributors
109109

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# 217. Contains Duplicate [![share]](https://leetcode.com/problems/contains-duplicate/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
11+
```
12+
Input: nums = [1,2,3,1]
13+
Output: true
14+
```
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
```
19+
Input: nums = [1,2,3,4]
20+
Output: false
21+
```
22+
23+
<p><strong class="example">Example 3:</strong></p>
24+
25+
```
26+
Input: nums = [1,1,1,3,3,4,3,2,4,2]
27+
Output: true
28+
```
29+
30+
<p> </p>
31+
<p><strong>Constraints:</strong></p>
32+
<ul>
33+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
34+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
35+
</ul>
36+
37+
## Solutions
38+
39+
### [_Rust_](contains_duplicate.rs)
40+
41+
```rs [Rust]
42+
impl Solution {
43+
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
44+
let mut set = std::collections::HashSet::new();
45+
46+
for num in nums {
47+
if set.contains(num) {
48+
return true;
49+
} else {
50+
set.insert(num);
51+
}
52+
}
53+
false
54+
}
55+
}
56+
57+
```
58+
59+
### [_..._]()
60+
61+
```
62+
63+
```
64+
65+
<!----------------------------------{ link }--------------------------------->
66+
67+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
68+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
69+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
70+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# 219. Contains Duplicate II [![share]](https://leetcode.com/problems/contains-duplicate-ii/)
2+
3+
![][easy]
4+
5+
## Problem Statement
6+
7+
<p>Given an integer array <code>nums</code> and an integer <code>k</code>, return <code>true</code> <em>if there are two <strong>distinct indices</strong> </em><code>i</code><em> and </em><code>j</code><em> in the array such that </em><code>nums[i] == nums[j]</code><em> and </em><code>abs(i - j) &lt;= k</code>.</p>
8+
<p> </p>
9+
<p><strong class="example">Example 1:</strong></p>
10+
11+
```
12+
Input: nums = [1,2,3,1], k = 3
13+
Output: true
14+
```
15+
16+
<p><strong class="example">Example 2:</strong></p>
17+
18+
```
19+
Input: nums = [1,0,1,1], k = 1
20+
Output: true
21+
```
22+
23+
<p><strong class="example">Example 3:</strong></p>
24+
25+
```
26+
Input: nums = [1,2,3,1,2,3], k = 2
27+
Output: false
28+
```
29+
30+
<p> </p>
31+
<p><strong>Constraints:</strong></p>
32+
<ul>
33+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
34+
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
35+
<li><code>0 &lt;= k &lt;= 10<sup>5</sup></code></li>
36+
</ul>
37+
38+
## Solutions
39+
40+
### [_Go_](contains_duplicate_II.go)
41+
42+
```go [Go]
43+
package main
44+
45+
func containsNearbyDuplicate(nums []int, k int) bool {
46+
if len(nums) <= 1 {
47+
return false
48+
}
49+
50+
set := make(map[int]int)
51+
52+
// iterate over the array
53+
for i, v := range nums {
54+
// check if the value is in the set
55+
if _, ok := set[v]; ok {
56+
// if the value is in the set,
57+
// check if the difference between the current index and the index of the value in the set
58+
// is less than or equal to k
59+
if i-set[v] <= k {
60+
return true
61+
}
62+
}
63+
// add the value to the set
64+
set[v] = i
65+
}
66+
67+
return false
68+
}
69+
70+
```
71+
72+
### [_..._]()
73+
74+
```
75+
76+
```
77+
78+
<!----------------------------------{ link }--------------------------------->
79+
80+
[share]: https://graph.org/file/3ea5234dda646b71c574a.png
81+
[easy]: https://img.shields.io/badge/Difficulty-Easy-bright.svg
82+
[medium]: https://img.shields.io/badge/Difficulty-Medium-yellow.svg
83+
[hard]: https://img.shields.io/badge/Difficulty-Hard-red.svg

src/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
| **0203** | [Remove Linked List Elements][203] | LL, Recursion | ![][easy] | |
7373
| **0205** | [Isomorphic Strings][205] | Hash Table, String | ![][easy] | |
7474
| **0206** | [Reverse Linked List][206] | Linked List, Recursion | ![][easy] | |
75+
| **0217** | [Contains Duplicate][217] | Array, Hash Table, Sorting | ![][easy] | |
76+
| **0219** | [Contains Duplicate II][219] | Array, Hash Table, Sliding Window | ![][easy] | |
7577
| **0222** | [Count Complete Tree Nodes][222] | Binary Search, Tree, DFS, Binary Tree | ![][medium] | |
7678
| **0230** | [Kth Smallest Element in a BST][230] | Tree, DFS, BST, Binary Tree | ![][medium] | |
7779
| **0231** | [Power of Two][231] | Math, Bit Manipulation, Recursion | ![][easy] | |
@@ -185,6 +187,8 @@
185187
[203]: ./0201-0300/203%20-%20Remove%20Linked%20List%20Elements/
186188
[205]: ./0201-0300/205%20-%20Isomorphic%20Strings/
187189
[206]: ./0201-0300/206%20-%20Reverse%20Linked%20List/
190+
[217]: ./0201-0300/217%20-%20Contains%20Duplicate/
191+
[219]: ./0201-0300/219%20-%20Contains%20Duplicate%20II/
188192
[222]: ./0201-0300/222%20-%20Count%20Complete%20Tree%20Nodes/
189193
[230]: ./0201-0300/230%20-%20Kth%20Smallest%20Element%20in%20a%20BST/
190194
[231]: ./0201-0300/231%20-%20Power%20of%20Two/

0 commit comments

Comments
 (0)