Skip to content

Commit ba96431

Browse files
authored
Merge branch 'main' into feat/week3
2 parents 278deb8 + e33cc14 commit ba96431

File tree

249 files changed

+7404
-3
lines changed

Some content is hidden

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

249 files changed

+7404
-3
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @DaleStudy/coach

.github/labeler.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
js:
2+
- changed-files:
3+
- any-glob-to-any-file:
4+
- "**/*.js"
5+
6+
ts:
7+
- changed-files:
8+
- any-glob-to-any-file:
9+
- "**/*.ts"
10+
11+
py:
12+
- changed-files:
13+
- any-glob-to-any-file:
14+
- "**/*.py"
15+
16+
java:
17+
- changed-files:
18+
- any-glob-to-any-file:
19+
- "**/*.java"
20+
21+
c++:
22+
- changed-files:
23+
- any-glob-to-any-file:
24+
- "**/*.cpp"
25+
26+
swift:
27+
- changed-files:
28+
- any-glob-to-any-file:
29+
- "**/*.swift"
30+
31+
kotlin:
32+
- changed-files:
33+
- any-glob-to-any-file:
34+
- "**/*.kt"
35+
36+
go:
37+
- changed-files:
38+
- any-glob-to-any-file:
39+
- "**/*.go"
40+
41+
elixir:
42+
- changed-files:
43+
- any-glob-to-any-file:
44+
- "**/*.exs"

.github/pull_request_template.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## 답안 제출 문제
2+
3+
<!--
4+
자신의 수준이나 일정에 맞게 금주에 푸시기로 정한 문제들만 나열해주세요.
5+
코드 검토자들이 PR 승인 여부를 결정할 때 도움이 됩니다.
6+
-->
7+
8+
- [ ] 문제 1
9+
- [ ] 문제 2
10+
- [ ] 문제 3
11+
12+
## 체크 리스트
13+
14+
- [ ] PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
15+
- [ ] 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
16+
- [ ] 문제를 모두 푸시면 프로젝트에서 Status를 `In Review`로 설정해주세요.
17+
- [ ] 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

.github/workflows/automation.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@ jobs:
1111
pull-requests: write
1212
steps:
1313
- uses: toshimaru/[email protected]
14+
15+
label-lang:
16+
runs-on: ubuntu-latest
17+
continue-on-error: true
18+
19+
permissions:
20+
contents: read
21+
pull-requests: write
22+
23+
steps:
24+
- uses: actions/labeler@v5
25+
with:
26+
repo-token: ${{ github.token }}

.github/workflows/integration.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: 🔄 Integration
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
linelint:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Find files missing end line break
15+
run: |
16+
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
17+
success=true
18+
for file in $files; do
19+
if [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then
20+
echo "- $file" >> $GITHUB_STEP_SUMMARY
21+
success=false
22+
fi
23+
done
24+
25+
if [ "$success" = false ]; then
26+
echo -e "\n:warning: 위 파일들의 끝에 누락된 줄 바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY
27+
exit 1
28+
fi

.linelint.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# 'true' will fix files
2+
autofix: false
3+
4+
# list of paths to ignore, uses gitignore syntaxes (executes before any rule)
5+
ignore:
6+
- "*.md"
7+
8+
rules:
9+
# checks if file ends in a newline character
10+
end-of-file:
11+
# set to true to enable this rule
12+
enable: true
13+
14+
# set to true to disable autofix (if enabled globally)
15+
disable-autofix: false
16+
17+
# if true also checks if file ends in a single newline character
18+
single-new-line: false

binary-tree-level-order-traversal/WhiteHyun.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ class Solution {
104104

105105
return array
106106
}
107-
}
107+
}

combination-sum/EGON.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def dfs(stack: List[int], sum: int, lower_bound_idx: int):
7777
candidates.sort()
7878
dfs([], 0, 0)
7979
return result
80-
80+
8181

8282
class _LeetCodeTestCases(TestCase):
8383
def test_1(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Definition for a binary tree node.
2+
class TreeNode {
3+
val: number;
4+
left: TreeNode | null;
5+
right: TreeNode | null;
6+
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
7+
this.val = val === undefined ? 0 : val;
8+
this.left = left === undefined ? null : left;
9+
this.right = right === undefined ? null : right;
10+
}
11+
}
12+
13+
// T.C: O(N)
14+
// S.C: O(N^2) - Slice makes n-1, n-2, ..., 1 for n times. So, it's O(N^2).
15+
function buildTree(preorder: number[], inorder: number[]): TreeNode | null {
16+
if (preorder.length === 0 || inorder.length === 0) {
17+
return null;
18+
}
19+
const root = new TreeNode(preorder[0]);
20+
const idx = inorder.indexOf(preorder[0]);
21+
root.left = buildTree(preorder.slice(1, idx + 1), inorder.slice(0, idx));
22+
root.right = buildTree(preorder.slice(idx + 1), inorder.slice(idx + 1));
23+
24+
return root;
25+
}
26+
27+
// Not using slice. but I think it's not necessary... first solution is more readable. and that's not so bad.
28+
// T.C: O(N)
29+
// S.C: O(N)
30+
function buildTree(preorder: number[], inorder: number[]): TreeNode | null {
31+
// this tree is consist of unique values
32+
const inorderMap = new Map<number, number>();
33+
for (const [i, val] of inorder.entries()) {
34+
inorderMap.set(val, i);
35+
}
36+
37+
function helper(preLeft: number, preRight: number, inLeft: number, inRight: number): TreeNode | null {
38+
if (preLeft > preRight) return null;
39+
40+
const rootValue = preorder[preLeft];
41+
const root = new TreeNode(rootValue);
42+
const inRootIdx = inorderMap.get(rootValue)!;
43+
44+
const leftSize = inRootIdx - inLeft;
45+
46+
root.left = helper(preLeft + 1, preLeft + leftSize, inLeft, inRootIdx - 1);
47+
root.right = helper(preLeft + leftSize + 1, preRight, inRootIdx + 1, inRight);
48+
49+
return root;
50+
}
51+
52+
return helper(0, preorder.length - 1, 0, inorder.length - 1);
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
private int i, p;
3+
public TreeNode buildTree(int[] preorder, int[] inorder) {
4+
// Time complexity: O(n)
5+
// Space complexity: O(n)
6+
return builder(preorder, inorder, Integer.MIN_VALUE);
7+
}
8+
9+
private TreeNode builder(int[] preorder, int[] inorder, int stop) {
10+
if (p >= preorder.length) return null;
11+
if (inorder[i] == stop) {
12+
i += 1;
13+
return null;
14+
}
15+
16+
TreeNode node = new TreeNode(preorder[p]);
17+
p += 1;
18+
19+
node.left = builder(preorder, inorder, node.val);
20+
node.right = builder(preorder, inorder, stop);
21+
return node;
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
class Solution:
8+
# T: O(N)
9+
# S: O(N)
10+
def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]:
11+
# preorder : root - left - right
12+
# inorder : left - root - right
13+
if not preorder and not inorder:
14+
return None
15+
16+
root = TreeNode(preorder[0])
17+
mid = inorder.index(preorder[0])
18+
19+
root.left = self.buildTree(preorder[1 : mid + 1], inorder[:mid])
20+
root.right = self.buildTree(preorder[mid + 1 :], inorder[mid+1:])
21+
22+
return root
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
17+
// time : O(n)
18+
// space : O(n)
19+
// n은 트리 노드 수
20+
21+
class Solution {
22+
23+
private int i = 0;
24+
Map<Integer, Integer> map = new HashMap<>();
25+
26+
public TreeNode buildTree(int[] preorder, int[] inorder) {
27+
28+
for(int i = 0; i < inorder.length; i++) {
29+
map.put(inorder[i], i);
30+
}
31+
32+
return build(preorder, inorder, 0, inorder.length);
33+
34+
}
35+
36+
private TreeNode build(int[] preorder, int[] inorder, int start, int end) {
37+
if(i >= preorder.length || start >= end) {
38+
return null;
39+
}
40+
41+
int value = preorder[i++];
42+
int index = map.get(value);
43+
44+
TreeNode leftTreeNode = build(preorder, inorder, start, index);
45+
TreeNode rightTreeNode = build(preorder, inorder, index+1, end);
46+
47+
return new TreeNode(value, leftTreeNode, rightTreeNode);
48+
}
49+
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* For the number of given nodes N,
3+
*
4+
* Time complexity: O(N)
5+
*
6+
* Space complexity: O(N) at worst
7+
*/
8+
9+
/**
10+
* Definition for a binary tree node.
11+
* struct TreeNode {
12+
* int val;
13+
* TreeNode *left;
14+
* TreeNode *right;
15+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
16+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
17+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
18+
* };
19+
*/
20+
class Solution {
21+
public:
22+
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
23+
unordered_map<int, int> inorder_index_map;
24+
stack<TreeNode*> tree_stack;
25+
26+
for (int i = 0; i < inorder.size(); i++) inorder_index_map[inorder[i]] = i;
27+
28+
TreeNode* root = new TreeNode(preorder[0]);
29+
tree_stack.push(root);
30+
31+
for (int i = 1; i < preorder.size(); i++) {
32+
TreeNode* curr = new TreeNode(preorder[i]);
33+
34+
if (inorder_index_map[curr->val] < inorder_index_map[tree_stack.top()->val]) {
35+
tree_stack.top()->left = curr;
36+
} else {
37+
TreeNode* parent;
38+
while (!tree_stack.empty() && inorder_index_map[curr->val] > inorder_index_map[tree_stack.top()->val]) {
39+
parent = tree_stack.top();
40+
tree_stack.pop();
41+
}
42+
parent->right = curr;
43+
}
44+
tree_stack.push(curr);
45+
}
46+
47+
return root;
48+
}
49+
};

0 commit comments

Comments
 (0)