Skip to content

Commit 56c3d9b

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 3b737e1 + 32d80da commit 56c3d9b

File tree

118 files changed

+3169
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+3169
-15
lines changed

contains-duplicate/DaleSeo.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::collections::HashSet;
2+
3+
// TC: O(n)
4+
// SC: O(n)
5+
impl Solution {
6+
pub fn contains_duplicate(nums: Vec<i32>) -> bool {
7+
let mut set = HashSet::new();
8+
!nums.into_iter().all(|num| set.insert(num))
9+
}
10+
}

contains-duplicate/Grit03.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
var containsDuplicate = function (nums) {
6+
const countMap = new Map();
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
const key = nums[i];
10+
if (countMap.has(key)) {
11+
const value = countMap.get(key);
12+
if (value === 1) {
13+
return true;
14+
}
15+
countMap.set(key, value + 1);
16+
} else {
17+
countMap.set(key, 1);
18+
}
19+
}
20+
21+
return false;
22+
};

contains-duplicate/SamTheKorean.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// TC : O(n) : it iterates for the length of nums
2+
// SC : O(n) : hashmap is created with the size of nums
3+
4+
func containsDuplicate(nums []int) bool {
5+
hashmap := make(map[int]bool)
6+
7+
for i:=0;i<len(nums);i++ {
8+
if hashmap[nums[i]] {
9+
return true
10+
}
11+
12+
hashmap[nums[i]] = true
13+
}
14+
15+
return false
16+
}
17+

contains-duplicate/bskkimm.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from collections import defaultdict
2+
class Solution(object):
3+
def containsDuplicate(self, nums):
4+
"""
5+
:type nums: List[int]
6+
:rtype: bool
7+
"""
8+
# [1,2,3,1]
9+
10+
# [1,1,1,3,3,4,3,2,4,2]
11+
12+
# add element to a dict
13+
# if a same value appears, then return True
14+
# if a for loop ends without disruption, return False
15+
16+
dict = defaultdict(bool)
17+
18+
for num in nums:
19+
if dict[num]:
20+
return True
21+
else:
22+
dict[num] = True
23+
24+
return False

contains-duplicate/chordpli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import List
2+
3+
class Solution:
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
dic = {}
6+
7+
for num in nums:
8+
if dic.get(num):
9+
return True
10+
dic[num] = 1
11+
12+
return False

contains-duplicate/devyejin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Solution(object):
2+
def containsDuplicate(self, nums):
3+
return len(nums) != len(set(nums))
4+

contains-duplicate/do-heewan.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def containsDuplicate(self, nums: List[int]) -> bool:
3+
sets = set(nums)
4+
5+
if len(nums) != len(sets):
6+
return True
7+
return False
8+

contains-duplicate/hj4645.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
# 리스트 안에 동일한 숫자가 2개 이상 존재하면 true를 반환해야 하는 문제
3+
# Set으로 변환 시 중복이 제거되므로 List와 Set의 크기를 비교해 답을 구할 수 있음
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
return len(nums) != len(set(nums))
6+
7+
# Time Complexity
8+
# - set(nums) → O(n)
9+
# - len(nums), len(set(nums)) → O(1)
10+
# - Total: O(n) (n = number of list elements)
11+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
time complexity : O(n)
3+
space complexity : O(n)
4+
*/
5+
class Solution {
6+
public boolean containsDuplicate(int[] nums) {
7+
HashSet<Integer> uniqueNums = new HashSet<Integer>();
8+
9+
for (int num:nums) {
10+
if (!uniqueNums.add(num)) {
11+
return true;
12+
}
13+
}
14+
return false;
15+
}
16+
}

contains-duplicate/hyer0705.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function containsDuplicate(nums: number[]): boolean {
2+
return new Set<number>(nums).size !== nums.length;
3+
}

0 commit comments

Comments
 (0)