Skip to content

Commit d2d4bb1

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 858ab7f + 3854db0 commit d2d4bb1

File tree

107 files changed

+2773
-5
lines changed

Some content is hidden

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

107 files changed

+2773
-5
lines changed

.github/workflows/integration.yaml

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ jobs:
1515
- name: Get PR labels
1616
id: pr-labels
1717
run: |
18+
echo "🔍 PR 번호: ${{ github.event.pull_request.number }}"
1819
pr_number="${{ github.event.pull_request.number }}"
20+
21+
echo "📋 PR 라벨 조회 중..."
1922
labels_json=$(gh pr view $pr_number --json labels -q '.labels[].name')
23+
echo "확인된 라벨: $labels_json"
24+
2025
if [ -n "$labels_json" ]; then
21-
echo "has_maintenance=$(echo $labels_json | grep -q 'maintenance' && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
26+
has_maintenance=$(echo $labels_json | grep -q 'maintenance' && echo 'true' || echo 'false')
27+
echo "maintenance 라벨 포함 여부: $has_maintenance"
28+
echo "has_maintenance=$has_maintenance" >> $GITHUB_OUTPUT
2229
else
30+
echo "maintenance 라벨이 없는 PR입니다. 파일명 규칙 검사를 진행합니다."
2331
echo "has_maintenance=false" >> $GITHUB_OUTPUT
2432
fi
2533
env:
@@ -28,35 +36,46 @@ jobs:
2836
# 줄바꿈 체크
2937
- name: Check for missing end line breaks
3038
run: |
31-
# 따옴표를 제거하고 파일 목록 가져오기
39+
echo "🔍 줄바꿈 검사 시작"
40+
echo "기준 커밋: ${{ github.event.pull_request.base.sha }}"
41+
echo "현재 커밋: ${{ github.sha }}"
42+
3243
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"')
3344
success=true
3445
35-
echo "변경된 파일 목록:"
46+
echo "📝 변경된 파일 목록:"
3647
echo "$files"
3748
3849
echo "## 줄바꿈 누락 파일" >> $GITHUB_STEP_SUMMARY
3950
for file in $files; do
51+
echo "검사 중: $file"
4052
if [ -s "$file" ] && [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then
41-
echo "발견된 줄바꿈 누락: $file"
53+
echo " 줄바꿈 누락: $file"
4254
echo "- $file" >> $GITHUB_STEP_SUMMARY
4355
success=false
56+
else
57+
echo "✅ 정상: $file"
4458
fi
4559
done
4660
4761
if [ "$success" = false ]; then
62+
echo "⚠️ 줄바꿈 검사 실패"
4863
echo -e "\n:warning: 파일 끝의 누락된 줄바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY
4964
exit 1
65+
else
66+
echo "✅ 모든 파일의 줄바꿈 정상"
5067
fi
5168
5269
# 제어문자 체크
5370
- name: Check for control characters in filenames
5471
run: |
72+
echo "🔍 파일명 제어문자 검사 시작"
5573
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr -d '"')
5674
success=true
5775
5876
echo "## 제어문자가 포함된 파일명" >> $GITHUB_STEP_SUMMARY
5977
for file in $files; do
78+
echo "검사 중: $file"
6079
# basename으로 파일명만 추출하고 따옴표 제거
6180
filename=$(basename "$file" | tr -d '"')
6281
@@ -71,43 +90,66 @@ jobs:
7190
7291
# 이스케이프 시퀀스 체크
7392
[[ "$filename" =~ (\\[0-7]{1,3}|\\x[0-9a-fA-F]{1,2}) ]]; then
93+
echo "❌ 제어문자 발견: $file"
7494
echo "- $file (제어문자 포함)" >> $GITHUB_STEP_SUMMARY
7595
success=false
96+
else
97+
echo "✅ 정상: $file"
7698
fi
7799
done
78100
79101
if [ "$success" = false ]; then
102+
echo "⚠️ 제어문자 검사 실패"
80103
echo -e "\n:warning: 파일명에서 제어문자를 제거해 주세요." >> $GITHUB_STEP_SUMMARY
81104
exit 1
105+
else
106+
echo "✅ 모든 파일명이 제어문자 없이 정상"
82107
fi
83108
84109
# 파일명 규칙 체크 - maintenance 라벨이 없는 경우에만 실행
85110
- name: Check filename rules
86111
if: ${{ steps.pr-labels.outputs.has_maintenance != 'true' }}
87112
run: |
88-
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | tr -d '"')
113+
echo "🔍 파일명 규칙 검사 시작"
114+
echo "PR 작성자: ${{ github.event.pull_request.user.login }}"
115+
116+
# PR의 공통 조상 커밋을 찾아서 merge base로 설정
117+
merge_base=$(git merge-base ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }})
118+
echo "Merge base 커밋: $merge_base"
119+
120+
files=$(git diff --name-only $merge_base ${{ github.event.pull_request.head.sha }} | tr -d '"')
89121
pr_author="${{ github.event.pull_request.user.login }}"
90122
success=true
91123
124+
echo "📝 검사할 파일 목록:"
125+
echo "$files"
126+
92127
echo "## 파일명 규칙 위반" >> $GITHUB_STEP_SUMMARY
93128
for file in $files; do
94129
if [ -f "$file" ]; then
95130
131+
echo "검사 중: $file"
96132
# 파일명만 추출 (경로 제외)
97133
filename=$(basename "$file")
98134
99135
# 파일명이 GitHub계정명인지 확인
100136
shopt -s nocasematch
101137
if [[ ! "$filename" = "$pr_author"* ]]; then
138+
echo "❌ 규칙 위반: $file"
102139
echo "- $file" >> $GITHUB_STEP_SUMMARY
103140
success=false
141+
else
142+
echo "✅ 정상: $file"
104143
fi
105144
fi
106145
done
107146
108147
if [ "$success" = false ]; then
148+
echo "⚠️ 파일명 규칙 검사 실패"
109149
echo -e "\n:warning: 파일명은 반드시 'GitHub계정명' 또는 'GitHub계정명-xxx' 형식으로 해주셔야 합니다. (예: ${pr_author}.ts, ${pr_author}-1.ts, ${pr_author}-2.ts)" >> $GITHUB_STEP_SUMMARY
110150
exit 1
151+
else
152+
echo "✅ 모든 파일명이 규칙에 맞게 정상"
111153
fi
112154
env:
113155
GH_TOKEN: ${{ github.token }}

3sum/GangBean.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
class Solution {
2+
public List<List<Integer>> threeSum(int[] nums) {
3+
/**
4+
1. understanding
5+
- integer array nums, find the whole combination of 3 nums, and the sum of the 3 nums equal to 0. And don't allow reusing same indiced number(but can duplicate in value)
6+
2. solve strategy
7+
- brute force
8+
- in every combination, validate sum of the nums equal to 0
9+
- but it can take O(N^3) times where N is the length of input array, and given that the N can be 3000 at most(3 * 10^3), time can be 27 * 10^9, which takes too long...
10+
- sort and two pointers
11+
- sort nums in ascending order, so move the left pointer to right means the sum of window is getting bigger.
12+
- and mid pointer set to left + 1 index
13+
- if sum of pointers is less than 0, then move mid pointer to right, until the sum is bigger than 0, and while processing them, if the sum of pointers is 0, then add the combination to the return list.
14+
- [-4, -1, -1, 0, 1, 2]:
15+
16+
3. complexity
17+
- time: O(N^2) -> each left pointer, you can search at most N-1, and left pointer's range is [0, N-1), so the max length is N-1 for left index pointer.
18+
- space: O(1) -> no extra space is needed
19+
*/
20+
// 0. assign return variable Set
21+
Set<List<Integer>> answer = new HashSet<>();
22+
23+
// 1. sort the num array in ascending order
24+
Arrays.sort(nums); // O(NlogN)
25+
// Arrays.stream(nums).forEach(System.out::println);
26+
27+
// 3. move the mid pointer from left to right to find the combination of which's sum is 0, and if the sum is over 0, and then move right pointer to the left. else if the sum is under 0, then move left pointer to right direction.
28+
for (int left = 0; left < nums.length - 1; left++) {
29+
int mid = left + 1;
30+
int right = nums.length - 1;
31+
while (mid < right) {
32+
// System.out.println(String.format("%d,%d,%d", nums[left], nums[mid], nums[right]));
33+
int sum = nums[left] + nums[mid] + nums[right];
34+
if (sum > 0) {
35+
right--;
36+
} else if (sum == 0) {
37+
answer.add(List.of(nums[left], nums[mid], nums[right]));
38+
right--;
39+
} else {
40+
mid++;
41+
}
42+
}
43+
}
44+
45+
return new ArrayList<>(answer);
46+
}
47+
}
48+

3sum/easyone-jwlee.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// 풀이
2+
// 배열을 정렬하고
3+
// two pointer 사용
4+
5+
// TC
6+
// 정렬 O(nlogn) + Two pointer 이중 루프 O(n^2) = O(n^2)
7+
8+
// SC
9+
// Go의 sort.Ints()는 TimSort를 사용.
10+
// Merge Sort와 Insertion Sort의 조합으로 동작.
11+
// 정렬 O(n) + Two pointer O(1) + 결과 배열 O(n) = O(n)
12+
13+
func threeSum(nums []int) [][]int {
14+
result := [][]int{}
15+
sort.Ints(nums) // nums를 정렬
16+
17+
for i := 0; i < len(nums)-2; i++ {
18+
if i > 0 && nums[i] == nums[i-1] {
19+
continue // 중복된 값 건너뜀
20+
}
21+
22+
left, right := i+1, len(nums)-1
23+
for left < right {
24+
sum := nums[i] + nums[left] + nums[right]
25+
if sum == 0 {
26+
result = append(result, []int{nums[i], nums[left], nums[right]})
27+
left++
28+
right--
29+
30+
// 중복 제거
31+
for left < right && nums[left] == nums[left-1] {
32+
left++
33+
}
34+
for left < right && nums[right] == nums[right+1] {
35+
right--
36+
}
37+
} else if sum < 0 {
38+
left++
39+
} else {
40+
right--
41+
}
42+
}
43+
}
44+
45+
return result
46+
}

climbing-stairs/GangBean.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public int climbStairs(int n) {
3+
/**
4+
1. Understanding
5+
- return the count of ways to climb up to top
6+
- way means the sequence of step count
7+
- each state, there can be 2 ways. first climb 1 step, second climb 2 step
8+
2. solve strategy
9+
- assume the count of ways to climb up to K th stairs is C[K].
10+
- then, C[0] = 1, C[1] = 1, C[2] = 2(because, you can up to 2nd stair from 0th stair and also from 1st stair.)
11+
- and C[3] = C[2] + C[1], C[4] = C[3] + C[2], ... etc...
12+
- so we can fomulate C[k] = C[k-1] + C[k-2]
13+
- iterate over 0 to n, you can caculate C[k].
14+
- and finally return C[n] is the answer.
15+
16+
3. complexity
17+
- I answer to this part, along with coding upon each line description.
18+
*/
19+
20+
// 1. create array to demonstrate each stairs way count to reach that position.
21+
// the maximun step count is 45, so maybe there is over 2^32(approximately 2 billion; so i worry about the overflow), I assign long type array. Oh.. but i catch that return type of this method is integer, so i can assume that maximum value is under integer range. So, assign as integer.
22+
int[] c = new int[n + 1]; // the extra plus 1 means 0th stair state
23+
// space complexity: O(n)
24+
for (int stair = 0; stair <= n; stair++) { // time complexity O(n)
25+
if (stair <= 1) {
26+
c[stair] = 1; // O(1)
27+
continue;
28+
}
29+
c[stair] = c[stair-1] + c[stair-2]; // O(1)
30+
}
31+
32+
return c[n];
33+
}
34+
}
35+

climbing-stairs/easyone-jwlee.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// 풀이
2+
// 1 일 때, 가능한 step은 1 -> 1가지
3+
// 2 일 때, 가능한 step은 1 1, 2 -> 2가지
4+
// 3 일 때, 가능한 step은 1 1 1, 1 2, 2 1 -> 3가지
5+
// n 일 때, 가능한 stop은 n-1의 가짓수에 1이 붙고, n-2의 가짓수에 2가 붙는다.
6+
7+
// TC
8+
// O(n)
9+
10+
// SC
11+
// int타입 변수만 사용해서 O(1)
12+
13+
func climbStairs(n int) int {
14+
if n <= 2 {
15+
return n
16+
}
17+
prev := 1 // climb1
18+
curr := 2 // climb2
19+
for i := 3; i <= n; i++ {
20+
prev, curr = curr, (curr + prev)
21+
}
22+
return curr
23+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode() {}
8+
* TreeNode(int val) { this.val = val; }
9+
* TreeNode(int val, TreeNode left, TreeNode right) {
10+
* this.val = val;
11+
* this.left = left;
12+
* this.right = right;
13+
* }
14+
* }
15+
*/
16+
class Solution {
17+
public TreeNode buildTree(int[] preorder, int[] inorder) {
18+
/**
19+
1. understanding
20+
- preorder: mid -> left -> right
21+
- inorder: left -> mid -> right
22+
- so, first element of the preorder array is always mid node.
23+
- if the idx of inorder's 1st depth mid node is k, then inorder[0:k-1] is the left tree part array. And also, preorder[k:] is the right tree part.
24+
2. strategy
25+
- find the inorder's mid node idx, and then split left tree part and right part, buildTree with each preorder and inorder part.
26+
27+
3. complexity
28+
- time: O(N^2)
29+
- space: O(N^2)
30+
*/
31+
if (preorder.length == 0) return null;
32+
if (preorder.length == 1) return new TreeNode(preorder[0]);
33+
int i = 0;
34+
List<Integer> leftPreorder = new ArrayList<>(); // O(N)
35+
List<Integer> leftInorder = new ArrayList<>(); // O(N)
36+
List<Integer> rightPreorder = new ArrayList<>(); // O(N)
37+
List<Integer> rightInorder = new ArrayList<>(); // O(N)
38+
for (; i < inorder.length; i++) { // O(N)
39+
if (inorder[i] == preorder[0]) break;
40+
leftPreorder.add(preorder[i+1]);
41+
leftInorder.add(inorder[i]);
42+
}
43+
for (int idx = i+1; idx < inorder.length; idx++) { // O(N)
44+
rightPreorder.add(preorder[idx]);
45+
rightInorder.add(inorder[idx]);
46+
}
47+
48+
return new TreeNode(preorder[0], buildTree(leftPreorder.stream().mapToInt(Integer::intValue).toArray(), leftInorder.stream().mapToInt(Integer::intValue).toArray()), buildTree(rightPreorder.stream().mapToInt(Integer::intValue).toArray(), rightInorder.stream().mapToInt(Integer::intValue).toArray()));
49+
}
50+
}
51+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// 풀이
2+
// preorder[0]이 제일 꼭대기
3+
// preorder 배열의 root index, inorder 배열의 시작, inorder 배열의 끝
4+
// 위의 세가지를 parameter로 받는 재귀함수를 만들어서
5+
// 왼쪽 서브트리, 오른쪽 서브트리를 순회
6+
7+
// TC
8+
// map 만들기 O(n) + 재귀함수는 각 노드를 딱 한번씩만 방문하므로 O(n) = O(n)
9+
10+
// SC
11+
// map O(n) + 재귀함수 최악의 경우 한쪽으로만 노드가 이어지는 경우 O(n) = O(n)
12+
13+
func buildTree(preorder []int, inorder []int) *TreeNode {
14+
inorderMap := make(map[int]int)
15+
for i, n := range inorder {
16+
inorderMap[n] = i
17+
}
18+
19+
var recursive func(rootIndex, inStart, inEnd int) *TreeNode
20+
recursive = func(rootIndex, inStart, inEnd int) *TreeNode {
21+
if rootIndex >= len(preorder) || inStart > inEnd {
22+
return nil
23+
}
24+
rootVal := preorder[rootIndex]
25+
rootInorderIndex := inorderMap[rootVal]
26+
27+
result := &TreeNode{
28+
Val: rootVal,
29+
}
30+
31+
leftSize := rootInorderIndex - inStart
32+
33+
result.Left = recursive(rootIndex+1, inStart, rootInorderIndex-1)
34+
result.Right = recursive(rootIndex+1+leftSize, rootInorderIndex+1, inEnd)
35+
36+
return result
37+
}
38+
39+
return recursive(0, 0, len(inorder)-1)
40+
}

contains-duplicate/EstherKim97.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
2+
3+
def containsDuplicate(nums):
4+
seen = set()
5+
for num in nums:
6+
if num in seen:
7+
return True
8+
seen.add(num)
9+
return False
10+

0 commit comments

Comments
 (0)