Skip to content

Commit b2cfa6d

Browse files
committed
feat: add python and java solutions to leetcode problem: No.0217
1 parent c198662 commit b2cfa6d

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

solution/0200-0299/0217.Contains Duplicate/README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,26 @@
3535
<!-- 这里可写当前语言的特殊实现逻辑 -->
3636

3737
```python
38-
38+
class Solution:
39+
def containsDuplicate(self, nums: List[int]) -> bool:
40+
return len(nums) != len(set(nums))
3941
```
4042

4143
### **Java**
4244

4345
<!-- 这里可写当前语言的特殊实现逻辑 -->
4446

4547
```java
46-
48+
class Solution {
49+
public boolean containsDuplicate(int[] nums) {
50+
Set<Integer> set = new HashSet<>();
51+
for (int e : nums) {
52+
if (set.contains(e)) return true;
53+
set.add(e);
54+
}
55+
return false;
56+
}
57+
}
4758
```
4859

4960
### **...**

solution/0200-0299/0217.Contains Duplicate/README_EN.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@
3939
### **Python3**
4040

4141
```python
42-
42+
class Solution:
43+
def containsDuplicate(self, nums: List[int]) -> bool:
44+
return len(nums) != len(set(nums))
4345
```
4446

4547
### **Java**
4648

4749
```java
48-
50+
class Solution {
51+
public boolean containsDuplicate(int[] nums) {
52+
Set<Integer> set = new HashSet<>();
53+
for (int e : nums) {
54+
if (set.contains(e)) return true;
55+
set.add(e);
56+
}
57+
return false;
58+
}
59+
}
4960
```
5061

5162
### **...**
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
class Solution {
22
public boolean containsDuplicate(int[] nums) {
3-
if(nums == null || nums.length == 0) return false;
43
Set<Integer> set = new HashSet<>();
5-
6-
for(int v : nums) {
7-
if(set.contains(v)) return true;
8-
set.add(v);
4+
for (int e : nums) {
5+
if (set.contains(e)) return true;
6+
set.add(e);
97
}
10-
118
return false;
129
}
1310
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def containsDuplicate(self, nums: List[int]) -> bool:
3+
return len(nums) != len(set(nums))

0 commit comments

Comments
 (0)