Skip to content

Commit 713ed94

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 452a791 + 9e91c8c commit 713ed94

File tree

240 files changed

+6469
-495
lines changed

Some content is hidden

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

240 files changed

+6469
-495
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function maxProfit(prices: number[]): number {
2+
let minPrice = Infinity;
3+
let maxProfit = 0;
4+
for (let i = 0; i < prices.length; i++) {
5+
if (prices[i] < minPrice) {
6+
minPrice = prices[i];
7+
}
8+
9+
if (prices[i] - minPrice > maxProfit) {
10+
maxProfit = prices[i] - minPrice;
11+
}
12+
}
13+
return maxProfit;
14+
}

contains-duplicate/HISEHOONAN.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Contains_Duplicate.swift
3+
// Algorithm
4+
//
5+
// Created by 안세훈 on 3/31/25.
6+
//
7+
8+
import Foundation
9+
10+
class Solution {
11+
func containsDuplicate(_ nums: [Int]) -> Bool {
12+
return nums.count != Set(nums).count
13+
//Set : 중복된 값을 갖지 않음.
14+
//문제로 주어진 배열의 개수와 중복을 갖지않는 Set연산의 개수의 차이 비교
15+
//비교 후 다르다면 true 같다면 false
16+
}
17+
}

contains-duplicate/HoonDongKang.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* [Problem]: [217] Contains Duplicate
3+
* (https://leetcode.com/problems/contains-duplicate/description/)
4+
*/
5+
6+
function containsDuplicate(nums: number[]): boolean {
7+
// 시간복잡도: O(n^2)
8+
// 공간복잡도: O(1)
9+
const doubleLoopFunc = (nums: number[]) => {
10+
let isDuplicated = false;
11+
for (let i = 0; i < nums.length; i++) {
12+
for (let j = i + 1; j < nums.length; j++) {
13+
if (nums[i] === nums[j]) isDuplicated = true;
14+
}
15+
}
16+
return isDuplicated;
17+
};
18+
19+
// 시간복잡도: O(n)
20+
// 공간복잡도: O(n)
21+
const setFunc = (nums: number[]) => {
22+
const numsSet = new Set<number>(nums);
23+
24+
return nums.length !== numsSet.size;
25+
};
26+
27+
// 시간복잡도: O(n)
28+
// 공간복잡도: O(n)
29+
const mapFunc = (nums: number[]) => {
30+
const numsMap = new Map<number, boolean>();
31+
32+
for (const num of nums) {
33+
if (numsMap.get(num)) return true;
34+
numsMap.set(num, true);
35+
}
36+
37+
return false;
38+
};
39+
40+
return mapFunc(nums);
41+
}

contains-duplicate/JANGSEYEONG.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
시간복잡도: O(n) - new Set(nums)에서 배열 요소 순회하며 Set 생성 O(n) + 길이 비교 O(1)
3+
- Set 자료구조는 중복된 값을 자동으로 제거
4+
*/
5+
6+
/**
7+
* @param {number[]} nums
8+
* @return {boolean}
9+
*/
10+
var containsDuplicate = function (nums) {
11+
// Set으로 만들었을 때, 기존 배열과 사이즈가 다르면 중복이 제거된거임
12+
const numsSet = new Set(nums);
13+
return nums.length !== numsSet.size;
14+
};

contains-duplicate/Jeehay28.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Approach 3: HashSet (Using TypeScript Set)
2+
// ⏳ Time Complexity: O(n)
3+
// 💾 Space Complexity: O(n)
4+
5+
function containsDuplicate(nums: number[]): boolean {
6+
7+
const seen = new Set<number>();
8+
9+
for (const num of nums) {
10+
if (seen.has(num)) {
11+
return true;
12+
}
13+
seen.add(num);
14+
}
15+
16+
return false;
17+
18+
};
19+
20+
21+
// Approach 2: Sorting + Scan
22+
// ⏳ Time Complexity: O(n * log(n)) ❌ (Faster than O(n^2), but still not optimal)
23+
// 💾 Space Complexity: O(1)
24+
25+
// function containsDuplicate(nums: number[]): boolean {
26+
27+
// nums.sort();
28+
29+
// for (let i = 0; i < nums.length - 1; i++) {
30+
// if (nums[i] === nums[i + 1]) {
31+
// return true;
32+
// }
33+
// }
34+
35+
// return false;
36+
37+
// };
38+
39+
40+
// Approach 1: Brute Force (O(n^2))
41+
// 🚨⏳ TLE (Time Limit Exceeded)!
42+
// ⏳ Time Complexity: O(n^2) ❌ (Inefficient for large inputs)
43+
// 💾 Space Complexity: O(1) ✅ (Great, no extra memory used!)
44+
45+
// function containsDuplicate(nums: number[]): boolean {
46+
47+
// for (let i = 0; i < nums.length; i++) {
48+
// for (let j = i + 1; j < nums.length; j++) {
49+
// if (nums[i] === nums[j]) {
50+
// return true;
51+
// }
52+
// }
53+
// }
54+
55+
// return false;
56+
57+
// };
58+
59+
60+

contains-duplicate/JiHyeonSu.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 중복제거 후 길이 확인 문제
2+
# 시간복잡도 및 공간복잡도 O(n)
3+
class Solution:
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
return len(nums) != len(set(nums))

contains-duplicate/JustHm.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution {
2+
func containsDuplicate(_ nums: [Int]) -> Bool {
3+
nums.count != Set(nums).count
4+
}
5+
}

contains-duplicate/KwonNayeon.py

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
"""
2-
Title: 217. Contains Duplicate
3-
Link: https://leetcode.com/problems/contains-duplicate/
2+
Problem: 217. Contains Duplicate
43
5-
Summary:
6-
- 주어진 배열 `nums`에서 어떤 값이 한 번 이상 등장하면 True를 반환하고, 배열의 모든 값이 유일한 경우에는 False를 반환함
7-
- Input: `nums = [1,2,3,1]`
8-
- Output: `True`
4+
Constraints:
5+
- 1 <= nums.length <= 10^5
6+
- -10^9 <= nums[i] <= 10^9
97
10-
Conditions:
11-
- 중복이 있으면: 배열에서 적어도 하나의 값이 두 번 이상 등장하면 `True` 반환
12-
- 중복이 없으면: 배열의 모든 값이 유일하면 `False` 반환
13-
"""
8+
Time Complexity: O(n)
9+
- 배열을 한 번만 순회함
10+
- 집합에서 검색과 추가 연산은 평균적으로 O(1)
11+
- 총 n개 요소에 대해 각각 O(1) 연산 수행
1412
15-
"""
16-
First Try
17-
Time Complexity:
18-
- O(n) * O(n) = O(n^2): `for` 루프에서 `nums.count(i)`를 호출할 때마다 리스트를 순회하므로, 전체 시간 복잡도는 `O(n^2)`
19-
"""
20-
class Solution:
21-
def containsDuplicate(self, nums: List[int]) -> bool:
22-
for i in nums:
23-
if nums.count(i) > 1:
24-
return True
25-
return False
26-
27-
"""
28-
Second Try (set를 활용하여 이미 본 요소를 효율적으로 추적하는 방법)
29-
Time Complexity:
30-
- O(n): `for` 루프에서 각 숫자에 대해 `in` 연산과 `add` 연산이 상수 시간 O(1)으로 처리되므로, 전체 시간 복잡도는 O(n)
13+
Space Complexity: O(n)
14+
- 최악의 경우 모든 요소를 집합에 저장
15+
- 추가 공간이 입력 배열 크기에 비례함
3116
"""
3217
class Solution:
3318
def containsDuplicate(self, nums: List[int]) -> bool:
3419
seen = set()
20+
3521
for i in nums:
3622
if i in seen:
3723
return True

contains-duplicate/PDKhan.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
bool containsDuplicate(vector<int>& nums) {
4+
unordered_map<int, int> map;
5+
6+
for(int i = 0; i < nums.size(); i++){
7+
map[nums[i]]++;
8+
9+
if(map[nums[i]] == 2)
10+
return true;
11+
}
12+
13+
return false;
14+
}
15+
};

contains-duplicate/Sung-Heon.py

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

0 commit comments

Comments
 (0)