-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
249 changed files
with
7,404 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @DaleStudy/coach |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
js: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.js" | ||
|
||
ts: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.ts" | ||
|
||
py: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.py" | ||
|
||
java: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.java" | ||
|
||
c++: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.cpp" | ||
|
||
swift: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.swift" | ||
|
||
kotlin: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.kt" | ||
|
||
go: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.go" | ||
|
||
elixir: | ||
- changed-files: | ||
- any-glob-to-any-file: | ||
- "**/*.exs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## 답안 제출 문제 | ||
|
||
<!-- | ||
자신의 수준이나 일정에 맞게 금주에 푸시기로 정한 문제들만 나열해주세요. | ||
코드 검토자들이 PR 승인 여부를 결정할 때 도움이 됩니다. | ||
--> | ||
|
||
- [ ] 문제 1 | ||
- [ ] 문제 2 | ||
- [ ] 문제 3 | ||
|
||
## 체크 리스트 | ||
|
||
- [ ] PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요. | ||
- [ ] 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요. | ||
- [ ] 문제를 모두 푸시면 프로젝트에서 Status를 `In Review`로 설정해주세요. | ||
- [ ] 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,16 @@ jobs: | |
pull-requests: write | ||
steps: | ||
- uses: toshimaru/[email protected] | ||
|
||
label-lang: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
|
||
permissions: | ||
contents: read | ||
pull-requests: write | ||
|
||
steps: | ||
- uses: actions/labeler@v5 | ||
with: | ||
repo-token: ${{ github.token }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: 🔄 Integration | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
linelint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Find files missing end line break | ||
run: | | ||
files=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }}) | ||
success=true | ||
for file in $files; do | ||
if [ "$(tail -c 1 $file | wc -l)" -eq 0 ]; then | ||
echo "- $file" >> $GITHUB_STEP_SUMMARY | ||
success=false | ||
fi | ||
done | ||
if [ "$success" = false ]; then | ||
echo -e "\n:warning: 위 파일들의 끝에 누락된 줄 바꿈을 추가해 주세요." >> $GITHUB_STEP_SUMMARY | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# 'true' will fix files | ||
autofix: false | ||
|
||
# list of paths to ignore, uses gitignore syntaxes (executes before any rule) | ||
ignore: | ||
- "*.md" | ||
|
||
rules: | ||
# checks if file ends in a newline character | ||
end-of-file: | ||
# set to true to enable this rule | ||
enable: true | ||
|
||
# set to true to disable autofix (if enabled globally) | ||
disable-autofix: false | ||
|
||
# if true also checks if file ends in a single newline character | ||
single-new-line: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,4 +104,4 @@ class Solution { | |
|
||
return array | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
construct-binary-tree-from-preorder-and-inorder-traversal/HC-kang.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Definition for a binary tree node. | ||
class TreeNode { | ||
val: number; | ||
left: TreeNode | null; | ||
right: TreeNode | null; | ||
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | ||
this.val = val === undefined ? 0 : val; | ||
this.left = left === undefined ? null : left; | ||
this.right = right === undefined ? null : right; | ||
} | ||
} | ||
|
||
// T.C: O(N) | ||
// S.C: O(N^2) - Slice makes n-1, n-2, ..., 1 for n times. So, it's O(N^2). | ||
function buildTree(preorder: number[], inorder: number[]): TreeNode | null { | ||
if (preorder.length === 0 || inorder.length === 0) { | ||
return null; | ||
} | ||
const root = new TreeNode(preorder[0]); | ||
const idx = inorder.indexOf(preorder[0]); | ||
root.left = buildTree(preorder.slice(1, idx + 1), inorder.slice(0, idx)); | ||
root.right = buildTree(preorder.slice(idx + 1), inorder.slice(idx + 1)); | ||
|
||
return root; | ||
} | ||
|
||
// Not using slice. but I think it's not necessary... first solution is more readable. and that's not so bad. | ||
// T.C: O(N) | ||
// S.C: O(N) | ||
function buildTree(preorder: number[], inorder: number[]): TreeNode | null { | ||
// this tree is consist of unique values | ||
const inorderMap = new Map<number, number>(); | ||
for (const [i, val] of inorder.entries()) { | ||
inorderMap.set(val, i); | ||
} | ||
|
||
function helper(preLeft: number, preRight: number, inLeft: number, inRight: number): TreeNode | null { | ||
if (preLeft > preRight) return null; | ||
|
||
const rootValue = preorder[preLeft]; | ||
const root = new TreeNode(rootValue); | ||
const inRootIdx = inorderMap.get(rootValue)!; | ||
|
||
const leftSize = inRootIdx - inLeft; | ||
|
||
root.left = helper(preLeft + 1, preLeft + leftSize, inLeft, inRootIdx - 1); | ||
root.right = helper(preLeft + leftSize + 1, preRight, inRootIdx + 1, inRight); | ||
|
||
return root; | ||
} | ||
|
||
return helper(0, preorder.length - 1, 0, inorder.length - 1); | ||
} |
23 changes: 23 additions & 0 deletions
23
construct-binary-tree-from-preorder-and-inorder-traversal/TomyKim9401.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class Solution { | ||
private int i, p; | ||
public TreeNode buildTree(int[] preorder, int[] inorder) { | ||
// Time complexity: O(n) | ||
// Space complexity: O(n) | ||
return builder(preorder, inorder, Integer.MIN_VALUE); | ||
} | ||
|
||
private TreeNode builder(int[] preorder, int[] inorder, int stop) { | ||
if (p >= preorder.length) return null; | ||
if (inorder[i] == stop) { | ||
i += 1; | ||
return null; | ||
} | ||
|
||
TreeNode node = new TreeNode(preorder[p]); | ||
p += 1; | ||
|
||
node.left = builder(preorder, inorder, node.val); | ||
node.right = builder(preorder, inorder, stop); | ||
return node; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
construct-binary-tree-from-preorder-and-inorder-traversal/coloryourlife.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Definition for a binary tree node. | ||
# class TreeNode: | ||
# def __init__(self, val=0, left=None, right=None): | ||
# self.val = val | ||
# self.left = left | ||
# self.right = right | ||
class Solution: | ||
# T: O(N) | ||
# S: O(N) | ||
def buildTree(self, preorder: List[int], inorder: List[int]) -> Optional[TreeNode]: | ||
# preorder : root - left - right | ||
# inorder : left - root - right | ||
if not preorder and not inorder: | ||
return None | ||
|
||
root = TreeNode(preorder[0]) | ||
mid = inorder.index(preorder[0]) | ||
|
||
root.left = self.buildTree(preorder[1 : mid + 1], inorder[:mid]) | ||
root.right = self.buildTree(preorder[mid + 1 :], inorder[mid+1:]) | ||
|
||
return root | ||
|
50 changes: 50 additions & 0 deletions
50
construct-binary-tree-from-preorder-and-inorder-traversal/f-exuan21.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Definition for a binary tree node. | ||
* public class TreeNode { | ||
* int val; | ||
* TreeNode left; | ||
* TreeNode right; | ||
* TreeNode() {} | ||
* TreeNode(int val) { this.val = val; } | ||
* TreeNode(int val, TreeNode left, TreeNode right) { | ||
* this.val = val; | ||
* this.left = left; | ||
* this.right = right; | ||
* } | ||
* } | ||
*/ | ||
|
||
// time : O(n) | ||
// space : O(n) | ||
// n은 트리 노드 수 | ||
|
||
class Solution { | ||
|
||
private int i = 0; | ||
Map<Integer, Integer> map = new HashMap<>(); | ||
|
||
public TreeNode buildTree(int[] preorder, int[] inorder) { | ||
|
||
for(int i = 0; i < inorder.length; i++) { | ||
map.put(inorder[i], i); | ||
} | ||
|
||
return build(preorder, inorder, 0, inorder.length); | ||
|
||
} | ||
|
||
private TreeNode build(int[] preorder, int[] inorder, int start, int end) { | ||
if(i >= preorder.length || start >= end) { | ||
return null; | ||
} | ||
|
||
int value = preorder[i++]; | ||
int index = map.get(value); | ||
|
||
TreeNode leftTreeNode = build(preorder, inorder, start, index); | ||
TreeNode rightTreeNode = build(preorder, inorder, index+1, end); | ||
|
||
return new TreeNode(value, leftTreeNode, rightTreeNode); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
construct-binary-tree-from-preorder-and-inorder-traversal/flynn.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* For the number of given nodes N, | ||
* | ||
* Time complexity: O(N) | ||
* | ||
* Space complexity: O(N) at worst | ||
*/ | ||
|
||
/** | ||
* Definition for a binary tree node. | ||
* struct TreeNode { | ||
* int val; | ||
* TreeNode *left; | ||
* TreeNode *right; | ||
* TreeNode() : val(0), left(nullptr), right(nullptr) {} | ||
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | ||
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | ||
* }; | ||
*/ | ||
class Solution { | ||
public: | ||
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) { | ||
unordered_map<int, int> inorder_index_map; | ||
stack<TreeNode*> tree_stack; | ||
|
||
for (int i = 0; i < inorder.size(); i++) inorder_index_map[inorder[i]] = i; | ||
|
||
TreeNode* root = new TreeNode(preorder[0]); | ||
tree_stack.push(root); | ||
|
||
for (int i = 1; i < preorder.size(); i++) { | ||
TreeNode* curr = new TreeNode(preorder[i]); | ||
|
||
if (inorder_index_map[curr->val] < inorder_index_map[tree_stack.top()->val]) { | ||
tree_stack.top()->left = curr; | ||
} else { | ||
TreeNode* parent; | ||
while (!tree_stack.empty() && inorder_index_map[curr->val] > inorder_index_map[tree_stack.top()->val]) { | ||
parent = tree_stack.top(); | ||
tree_stack.pop(); | ||
} | ||
parent->right = curr; | ||
} | ||
tree_stack.push(curr); | ||
} | ||
|
||
return root; | ||
} | ||
}; |
Oops, something went wrong.