Skip to content

Commit

Permalink
Merge pull request #730 from oyeong011/main
Browse files Browse the repository at this point in the history
[oyeong011] week2
  • Loading branch information
SamTheKorean authored Dec 22, 2024
2 parents da886dd + bfa66f6 commit 0e775c1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions climbing-stairs/oyeong011.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
public:
int climbStairs(int n) {
if(n == 0 || n == 1){
return 1;
}
vector<int> dp(n + 1);
dp[0] = dp[1] = 1;
for(int i = 2; i <= n; i++){
dp[i] = dp[i-1] + dp[i - 2];
}
return dp[n];
}
};

// dp ๋ฌธ์ œ๋กœ ๋ฐฐ์—ด์„ ์ƒ์„ฑํ•ด์ค€๋‹ค
// ๊ณ„๋‹จ ๋ฐฉ์‹
// 1 1๊ฐœ
// 1 + 1, 2 2๊ฐœ
// 1 + 1 + 1, 2 + 1, 1 + 2 3๊ฐœ
// 1 + 1 + 1 + 1, 1 + 1 + 2, 1 + 2 + 1, 2 + 1 + 1, 2 + 2 ---> 5๊ฐœ
// ์ฆ‰ ํ”ผ๋ณด๋‚˜์ฐŒ ์ˆ˜์—ด์˜ ํ˜•ํƒœ๋ฅผ ๋ˆ๋‹ค ์™œ๋ƒ๋ฉด 2์นธ์„ ๋›ฐ๊ธฐ ๋•Œ๋ฌธ์— ํ•œ์นธ์ „์— 1์„ ๋”ํ•˜๊ณ  ๋‘์นธ ์ „์— ๊ฒฝ์šฐ์˜ ์ˆ˜์— 2๋ฅผ ๋”ํ•ด์ฃผ๋ฉด ๋˜๊ธฐ๋•Œ๋ฌธ
// ์ฆ‰ f(n) = f(n - 1) + f(n - 2)
// ๋งŒ์•ฝ ๊ณ„๋‹จ ๋ฐฉ์‹์ด 3์นธ๊นŒ์ง€์ด๋ฉด ์ฆ‰ f(n) = f(n - 1) + f(n - 2) + f(n - 3)
// ์‹œ๊ฐ„๋ณต์žก๋„๋Š” n๋งŒํผ ์ˆœํšŒํ•˜์—ฌ O(n)
15 changes: 15 additions & 0 deletions valid-anagram/oyeong011.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution {
public:
bool isAnagram(string s, string t) {
unordered_map<char, int> ss, tt;
if(s.length() != t.length())return false;
for(auto i : s) ss[i]++;
for(auto i : t) tt[i]++;
return ss == tt;
}
};

// ๋ฌธ์ž์—ด ๋น„๊ต unordered_map์€ ํ•ด์‰ฌ ํ˜•ํƒœ์ด๋ฏ€๋กœ O(1)
// ๊ฐ ๋ฌธ์ž ๋ฃจํ”„ O(n)
// ๋งˆ์ง€๋ง‰ ๋ฌธ์ž ๋น„๊ต ํ•ด์‹œ๋ฉฅ ์•ŒํŒŒ๋ฒณ์€ 26๊ฐœ ์ด๋ฏ€๋กœ O(n)
// ๋”ฐ๋ผ์„œ O(n)

0 comments on commit 0e775c1

Please sign in to comment.