Skip to content

Commit 67296f6

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 399b3a3 + 4b99484 commit 67296f6

148 files changed

Lines changed: 3536 additions & 7 deletions

File tree

Some content is hidden

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

3sum/alphaorderly.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Solution:
2+
def threeSum(self, nums: list[int]) -> list[list[int]]:
3+
"""
4+
O(N^2)
5+
"""
6+
cntr = Counter(nums)
7+
8+
ans = []
9+
10+
# First case -> [0, 0, 0] Triplet
11+
if cntr[0] >= 3:
12+
ans.append([0, 0, 0])
13+
14+
# Second case -> two same numbers + one diff number
15+
for k, v in cntr.items():
16+
if k == 0:
17+
continue
18+
if v >= 2 and -(k * 2) in cntr:
19+
ans.append([k, k, -(k * 2)])
20+
21+
s = set(nums)
22+
nums = list(s)
23+
nums.sort()
24+
25+
pos = {k: v for v, k in enumerate(nums)}
26+
N = len(nums)
27+
28+
# Third case -> all different numbers
29+
for i in range(N - 2):
30+
for j in range(i + 1, N - 1):
31+
target = -(nums[i] + nums[j])
32+
if target in pos:
33+
k = pos[target]
34+
if k > j:
35+
ans.append([nums[i], nums[j], nums[k]])
36+
37+
return ans

3sum/dolphinflow86.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# 1) Fix one element first, and then treat others as two-sum problem. Use set to get rid of duplicate combination.
2+
# TC: O(N^2) where N is the length of nums.
3+
# SC: O(N) where N is the length of nums.
4+
class Solution:
5+
def threeSum(self, nums: list[int]) -> list[list[int]]:
6+
answer: Set[tuple[int,int,int]] = set()
7+
n = len(nums)
8+
nums.sort()
9+
10+
for i in range(n-2):
11+
if i > 0 and nums[i] == nums[i-1]: continue
12+
13+
target = -nums[i]
14+
nums_map: Dict[int, int] = {}
15+
for j in range(i + 1, n):
16+
comp = target - nums[j]
17+
if comp in nums_map:
18+
answer.add((nums[i], comp, nums[j]))
19+
nums_map[nums[j]] = j
20+
21+
return [list(triplet) for triplet in answer]

3sum/yuseok89.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# TC: O(N^2)
2+
# SC: O(N)
3+
class Solution:
4+
def threeSum(self, nums: list[int]) -> list[list[int]]:
5+
6+
cnt_dict = Counter(nums)
7+
nums_uniq = sorted(cnt_dict.keys())
8+
n = len(nums_uniq)
9+
10+
ret = []
11+
12+
for num in cnt_dict.keys():
13+
if num == 0:
14+
if cnt_dict[num] >= 3:
15+
ret.append([0, 0, 0])
16+
elif cnt_dict[num] >= 2 and num * 2 * -1 in cnt_dict:
17+
ret.append([num, num, num * 2 * -1])
18+
19+
for idx1, num1 in enumerate(nums_uniq):
20+
if num1 > 0:
21+
break
22+
23+
for idx2 in range(idx1 + 1, n):
24+
num2 = nums_uniq[idx2]
25+
num3 = (num1 + num2) * -1
26+
27+
if num2 >= num3:
28+
break
29+
elif num3 in cnt_dict:
30+
ret.append([num1, num2, num3])
31+
32+
return ret
33+

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
## 차수
1212

13-
- 7기 (Mar 1, 2025 - Jun 13, 2026): [프로젝트](https://github.com/orgs/DaleStudy/projects/26/views/3), [](https://github.com/orgs/DaleStudy/teams/leetcode07)
13+
- 8기 (Jun 21, 2026 - Oct 3, 2026): [프로젝트](https://github.com/orgs/DaleStudy/projects/29/views/2), [](https://github.com/orgs/DaleStudy/teams/leetcode08)
14+
- 7기 (Mar 1, 2026 - Jun 13, 2026): [프로젝트](https://github.com/orgs/DaleStudy/projects/26/views/3), [](https://github.com/orgs/DaleStudy/teams/leetcode07)
1415
- 6기 (Nov 8, 2025 - Feb 20, 2026): [프로젝트](https://github.com/orgs/DaleStudy/projects/23/views/3), [](https://github.com/orgs/DaleStudy/teams/leetcode06)
1516
- 5기 (Jul 20, 2025 - Nov 1, 2025): [프로젝트](https://github.com/orgs/DaleStudy/projects/16/views/3), [](https://github.com/orgs/DaleStudy/teams/leetcode05)
1617
- 4기 (Mar 30, 2025 - Jul 12, 2025): [프로젝트](https://github.com/orgs/DaleStudy/projects/13/views/3), [](https://github.com/orgs/DaleStudy/teams/leetcode04)

climbing-stairs/alphaorderly.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# class Solution:
2+
# def climbStairs(self, n: int) -> int:
3+
# """
4+
# O(N) with additional space
5+
# """
6+
# if n <= 2:
7+
# return n
8+
9+
# dp = [0] * (n + 1)
10+
# dp[1] = 1
11+
# dp[2] = 2
12+
13+
# for i in range(3, n + 1):
14+
# dp[i] = dp[i - 1] + dp[i - 2]
15+
16+
# return dp[-1]
17+
18+
# class Solution:
19+
# """
20+
# O(N) Found that solution is fibonacci number
21+
# """
22+
# def climbStairs(self, n: int) -> int:
23+
# if n <= 2:
24+
# return n
25+
26+
# p1, p2 = 1, 2
27+
# for i in range(3, n + 1):
28+
# p1, p2 = p2, p1 + p2
29+
30+
# return p2
31+
32+
33+
# Fibonacci hack
34+
class Solution:
35+
def climbStairs(self, n: int) -> int:
36+
"""
37+
O(Log N)
38+
"""
39+
40+
# O(1) operation
41+
def mat_mul(a: List[List[int]], b: List[List[int]]) -> List[List[int]]:
42+
ans = [[0] * 2 for _ in range(2)]
43+
44+
for i in range(2):
45+
for j in range(2):
46+
for k in range(2):
47+
ans[i][j] += a[i][k] * b[k][j]
48+
49+
return ans
50+
51+
# O(Log N) operation
52+
def mat_pow(a: List[List[int]], n: int) -> List[List[int]]:
53+
if n == 1:
54+
return [[1, 1], [1, 0]]
55+
56+
half = mat_pow(a, n // 2)
57+
multed = mat_mul(half, half)
58+
59+
if n % 2:
60+
return mat_mul(multed, [[1, 1], [1, 0]])
61+
else:
62+
return multed
63+
64+
ans = mat_pow([[1, 1], [1, 0]], n)
65+
66+
return ans[0][0]

climbing-stairs/dolphinflow86.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 1) Recursion with memoization.
2+
# TC: O(N) where N is the given natural number.
3+
# SC: O(N) where N is the given natural number.
4+
class Solution:
5+
def climb_rec(self, n: int, step: int, memo: Dict[int, int]):
6+
if step > n: return 0
7+
if step in memo: return memo[step]
8+
if step == n: return 1
9+
10+
first_way = self.climb_rec(n, step + 1, memo)
11+
second_way = self.climb_rec(n, step + 2, memo)
12+
memo[step] = first_way + second_way
13+
return memo[step]
14+
15+
16+
def climbStairs(self, n: int) -> int:
17+
if n == 1: return 1
18+
19+
memo = {}
20+
return self.climb_rec(n, 1, memo) + self.climb_rec(n, 2, memo)

climbing-stairs/yuseok89.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# TC: O(N)
2+
# SC: O(1)
3+
class Solution:
4+
def climbStairs(self, n: int) -> int:
5+
6+
one_down = 1
7+
two_down = 0
8+
9+
for _ in range(1, n):
10+
cur = two_down + one_down
11+
two_down = one_down
12+
one_down = cur
13+
14+
return two_down + one_down
15+

contains-duplicate/Chanz82.py

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

contains-duplicate/ICE0208.py

Lines changed: 3 additions & 0 deletions
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(set(nums)) != len(nums)

contains-duplicate/JeonJe.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import java.util.*;
2+
3+
// TC: O(n)
4+
// SC: O(n)
5+
class Solution {
6+
public boolean containsDuplicate(int[] nums) {
7+
Set<Integer> set = new HashSet<>();
8+
for (int num : nums) {
9+
if (set.contains(num)) {
10+
return true;
11+
}
12+
set.add(num);
13+
}
14+
return false;
15+
}
16+
}

0 commit comments

Comments
 (0)