Skip to content

Commit

Permalink
Merge branch 'main' into feat/week3
Browse files Browse the repository at this point in the history
  • Loading branch information
lymchgmk authored Aug 28, 2024
2 parents 0a4e7f1 + f0ba3e8 commit c218258
Show file tree
Hide file tree
Showing 260 changed files with 7,657 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DaleStudy/coach
44 changes: 44 additions & 0 deletions .github/labeler.yml
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"
17 changes: 17 additions & 0 deletions .github/pull_request_template.md
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을 병합해주세요.
13 changes: 13 additions & 0 deletions .github/workflows/automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
28 changes: 28 additions & 0 deletions .github/workflows/integration.yaml
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
18 changes: 18 additions & 0 deletions .linelint.yml
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
2 changes: 1 addition & 1 deletion binary-tree-level-order-traversal/WhiteHyun.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ class Solution {

return array
}
}
}
13 changes: 13 additions & 0 deletions climbing-stairs/flynn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public:
int climbStairs(int n) {
vector<int> memo(2, 1);

for (int i = 2; i <= n; i++) {
memo.push_back(memo[i - 1] + memo[i - 2]);
}

return memo[n];
}

};
2 changes: 1 addition & 1 deletion coin-change/EGON.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def solveWithDP(self, coins: List[int], amount: int) -> int:

if amount < coins[0]:
return -1

dp = [float('inf')] * (amount + 1)

for coin in coins:
Expand Down
19 changes: 19 additions & 0 deletions coin-change/flynn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
public:
int coinChange(vector<int>& coins, int amount) {
int MAX = 10000 + 1;
vector<int> memo(amount + 1, MAX);
memo[0] = 0;

for (int i = 1; i <= amount; i++) {
for (auto coin : coins) {
if (i - coin >= 0) {
memo[i] = min(memo[i], memo[i - coin] + 1);
}
}
}

return memo[amount] == MAX ? -1 : memo[amount];
}

};
1 change: 0 additions & 1 deletion combination-sum/EGON.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def dfs(stack: List[int], sum: int, lower_bound_idx: int):
dfs([], 0, 0)
return result


class _LeetCodeTestCases(TestCase):
def test_1(self):
candidates = [2, 3, 6, 7]
Expand Down
43 changes: 43 additions & 0 deletions combination-sum/flynn.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Solution {
public:
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
vector<vector<int>> res;
queue<pair<int, pair<int, vector<int>>>> q; // {acc, {idx, combination}}

for (int i = 0; i < candidates.size(); i++) {
int num = candidates[i];

if (num <= target) {
vector<int> comb;
comb.push_back(num);
q.push({num, {i, comb}});
}

}

while (!q.empty()) {
auto p = q.front();
q.pop();

int acc = p.first, idx = p.second.first;
auto comb = p.second.second;

if (acc == target) {
res.push_back(comb);
} else if (acc < target) {
for (int i = idx; i < candidates.size(); i++) {
int num = candidates[i];

if (acc + num <= target) {
vector<int> new_comb(comb);
new_comb.push_back(num);
q.push({acc + num, {i, new_comb}});
}
}
}
}

return res;
}

};
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);
}
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;
}
}
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

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);
}

}
Loading

0 comments on commit c218258

Please sign in to comment.