Skip to content

Commit e02a926

Browse files
authored
Merge branch 'DaleStudy:main' into main
2 parents 788607c + 01e005a commit e02a926

Some content is hidden

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

58 files changed

+1685
-25
lines changed

โ€Ž.github/labeler.ymlโ€Ž

Lines changed: 44 additions & 0 deletions
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/workflows/automation.yamlโ€Ž

Lines changed: 13 additions & 0 deletions
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 }}

โ€Žclimbing-stairs/HC-kang.tsโ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// T.C. O(n)
2+
// S.C. O(1)
3+
function climbStairs(n: number): number {
4+
let p = 0;
5+
let q = 1;
6+
for (let i = 0; i < n; i++) {
7+
q = q + p;
8+
p = q - p;
9+
}
10+
return q;
11+
}

โ€Žclimbing-stairs/bemelon.pyโ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
# Space complexity: O(1)
3+
# Tiem complexity: O(n)
4+
def climbStairs(self, n: int) -> int:
5+
# dp[0] is n - 2
6+
# dp[1] is n - 1
7+
dp = [1, 2]
8+
9+
if n <= 2:
10+
return dp[n - 1]
11+
12+
for i in range(3, n + 1):
13+
# dp[n] = dp[n - 1] + dp[n - 2]
14+
# = dp[1] + dp[0]
15+
dp[(i - 1) % 2] = sum(dp)
16+
17+
return dp[(n - 1) % 2]

โ€Žclimbing-stairs/flynn.cppโ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public:
3+
int climbStairs(int n) {
4+
vector<int> memo(2, 1);
5+
6+
for (int i = 2; i <= n; i++) {
7+
memo.push_back(memo[i - 1] + memo[i - 2]);
8+
}
9+
10+
return memo[n];
11+
}
12+
13+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time Complexity: O(n)
2+
// Spatial Complexity: O(n)
3+
4+
class Solution {
5+
public:
6+
int climbStairs(int n) {
7+
vector<int> dp(n + 1, 0);
8+
9+
if (n == 1) {
10+
return 1;
11+
}
12+
13+
dp[0] = dp[1] = 1;
14+
for(int i = 2; i <= n; ++i) {
15+
dp[i] = dp[i - 1] + dp[i - 2];
16+
}
17+
18+
return dp[n];
19+
}
20+
};

โ€Žclimbing-stairs/jdalma.ktโ€Ž

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package leetcode_study
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.junit.jupiter.api.Test
5+
6+
class `climbing-stairs` {
7+
8+
/**
9+
* 1. bottom-up ๋ฐฉ์‹์œผ๋กœ ๊ฐ€๋Šฅํ•œ ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ˆ„์ ํ•œ๋‹ค.
10+
* TC: O(n), SC: O(n)
11+
*/
12+
fun climbStairs(n: Int): Int {
13+
val dp = IntArray(n + 1).apply {
14+
this[1] = 1
15+
if (n >= 2) this[2] = 2
16+
}
17+
18+
for (num in 3 .. n) {
19+
dp[num] = dp[num - 1] + dp[num - 2]
20+
}
21+
22+
return dp[n]
23+
}
24+
25+
@Test
26+
fun `์ž…๋ ฅ๋ฐ›์€ ๋ชฉํ‘ฏ๊ฐ’์— 1๊ณผ 2๋งŒ ๋”ํ•˜์—ฌ ๋„๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค`() {
27+
climbStairs(1) shouldBe 1
28+
climbStairs(2) shouldBe 2
29+
climbStairs(3) shouldBe 3
30+
climbStairs(4) shouldBe 5
31+
}
32+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// found a pattern where the result is the addition of two previous elements,
2+
// but not sure if this is the expected answer
3+
var climbStairs = function (n) {
4+
let arr = new Array(n).fill(1);
5+
for (let i = 2; i <= n; i++) {
6+
arr[i] = arr[i - 2] + arr[i - 1];
7+
}
8+
return n === 1 ? 1 : arr[n];
9+
};
10+
11+
// time - O(n) iterate up to n times
12+
// space - O(n) creates an array upto n elements
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @description
3+
* brainstorming:
4+
* Dynamic Programming
5+
*
6+
* time complexity: O(n)
7+
* space complexity: O(n)
8+
*/
9+
10+
var climbStairs = function (n) {
11+
const dp = Array.from({ length: n + 1 }, () => 0);
12+
dp[1] = 1;
13+
dp[2] = 2;
14+
15+
for (let i = 3; i < n + 1; i++) dp[i] = dp[i - 1] + dp[i - 2];
16+
17+
return dp[n];
18+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(n)
3+
* - n = 5 ๊ฒฝ์šฐ๋ฅผ ๊ฐ€์ •ํ•˜๊ณ  ์ƒ๊ฐํ•ด๋ณด๊ธฐ
4+
* - 3์ธต ๊ณ„๋‹จ -> 2์ธต, 1์ธต ๊ณ„์‚ฐ (์ด ๊ฒฝ์šฐ๋Š” ์ด๋ฏธ ๋ฉ”๋ชจ๋˜์–ด ์žˆ์–ด์„œ ๋ณ„๋„๋กœ ๊ณ„์‚ฐํ•˜์ง„ ์•Š์Œ)
5+
* - 4์ธต ๊ณ„๋‹จ -> 3์ธต, 2์ธต ๊ณ„์‚ฐ (2์ธต์€ ๋ฉ”๋ชจ์— ์žˆ๋Š” ๊ฒƒ ํ™œ์šฉ)
6+
* - 5์ธต ๊ณ„๋‹จ -> 4์ธต, 3์ธต ๊ณ„์‚ฐ (3์ธต์€ ๋ฉ”๋ชจ์— ์žˆ๋Š” ๊ฒƒ ํ™œ์šฉ)
7+
* - ...
8+
* - ๊ฐ ๋‹จ๊ณ„ ๋ณ„๋กœ (๋ฉ”๋ชจ๋ฅผ ํ™œ์šฉํ•ด) ์•„์ง ๊ณ„์‚ฐ๋˜์ง€ ์•Š์€ ๊ฒƒ์„ ํ•œ ๋ฒˆ์”ฉ ํ˜ธ์ถœํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ O(n)
9+
* - ๊ทผ๋ฐ ๋งŒ์•ฝ ๋ฉ”๋ชจ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด? (์ค‘๋ณต ํ˜ธ์ถœ์ด ๋งŽ์ด ์ผ์–ด๋‚จ ... O(n^2))
10+
*
11+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(n)
12+
*/
13+
class Solution {
14+
public int climbStairs(int n) {
15+
int[] memo = new int[n + 1];
16+
return climbStairs(n, memo);
17+
}
18+
19+
public int climbStairs(int n, int[] memo) {
20+
if (n == 1) return 1;
21+
if (n == 2) return 2;
22+
23+
if (memo[n] > 0) return memo[n];
24+
25+
memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo);
26+
return memo[n];
27+
}
28+
}

0 commit comments

Comments
ย (0)