Skip to content

Commit d5f8ddc

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 2c55997 + 1d40150 commit d5f8ddc

File tree

197 files changed

+5296
-207
lines changed

Some content is hidden

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

197 files changed

+5296
-207
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/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/JisuuungKim.py

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

contains-duplicate/RiaOh.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
var containsDuplicate = function (nums) {
6+
let count = [nums[0]];
7+
for (let i = 1; i < nums.length; i++) {
8+
if (count.includes(nums[i])) {
9+
return true;
10+
} else {
11+
count.push(nums[i]);
12+
}
13+
}
14+
return false;
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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.HashMap;
2+
import java.util.Map;
3+
4+
class Solution {
5+
// 시간복잡도 O(n)
6+
public boolean containsDuplicate(int[] nums) {
7+
Map<Integer, Boolean> dupMap = new HashMap<>();
8+
9+
for(int i = 0; i < nums.length; i++) {
10+
if(dupMap.containsKey(nums[i])) {
11+
return true;
12+
}
13+
14+
dupMap.put(nums[i], true);
15+
}
16+
17+
return false;
18+
}
19+
}

contains-duplicate/ayleeee.py

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

contains-duplicate/b41-41.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// nums에 중복이 있는 지 확인하는 것
2+
// array써서 시간 통과 못했다가 Set 객체로 변경해서 통과
3+
function containsDuplicate(nums: number[]): boolean {
4+
const numSet = new Set();
5+
6+
for(let num of nums) {
7+
if(numSet.has(num)) {
8+
return true;
9+
} else {
10+
numSet.add(num);
11+
}
12+
}
13+
14+
return false;
15+
};

0 commit comments

Comments
 (0)