From 9871f0b238bb29476ee6f4b4f2fcb3aa575c1b61 Mon Sep 17 00:00:00 2001 From: oyeong011 Date: Tue, 17 Dec 2024 15:54:40 +0900 Subject: [PATCH 1/5] valid-anagram sol --- valid-anagram/oyeong011.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 valid-anagram/oyeong011.cpp diff --git a/valid-anagram/oyeong011.cpp b/valid-anagram/oyeong011.cpp new file mode 100644 index 000000000..3982e8154 --- /dev/null +++ b/valid-anagram/oyeong011.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + bool isAnagram(string s, string t) { + unordered_map ss, tt; + if(s.length() != t.length())return false; + for(auto i : s) ss[i]++; + for(auto i : t) tt[i]++; + return ss == tt; + } +}; From bddaee7482ffc16fab5d32c3f59f2e41bd2db853 Mon Sep 17 00:00:00 2001 From: oyeong011 Date: Tue, 17 Dec 2024 15:55:04 +0900 Subject: [PATCH 2/5] valid-anagram sol --- valid-anagram/oyeong011.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/valid-anagram/oyeong011.cpp b/valid-anagram/oyeong011.cpp index 3982e8154..4fe50c388 100644 --- a/valid-anagram/oyeong011.cpp +++ b/valid-anagram/oyeong011.cpp @@ -8,3 +8,4 @@ class Solution { return ss == tt; } }; + From da5385cb16f3c2b796deea3c0bf404f1a53cb85a Mon Sep 17 00:00:00 2001 From: oyeong011 Date: Tue, 17 Dec 2024 15:58:45 +0900 Subject: [PATCH 3/5] valid-anagram sol --- valid-anagram/oyeong011.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/valid-anagram/oyeong011.cpp b/valid-anagram/oyeong011.cpp index 4fe50c388..905dd6f8e 100644 --- a/valid-anagram/oyeong011.cpp +++ b/valid-anagram/oyeong011.cpp @@ -9,3 +9,7 @@ class Solution { } }; +// 문자열 비교 unordered_map은 해쉬 형태이므로 O(1) +// 각 문자 루프 O(n) +// 마지막 문자 비교 해시멥 알파벳은 26개 이므로 O(n) +// 따라서 O(n) \ No newline at end of file From 626d390db00539afe0685ef73c36003c84de3353 Mon Sep 17 00:00:00 2001 From: oyeong011 Date: Tue, 17 Dec 2024 16:09:17 +0900 Subject: [PATCH 4/5] =?UTF-8?q?valid-anagram=20sol=20=EC=A4=84=EB=B0=94?= =?UTF-8?q?=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-anagram/oyeong011.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valid-anagram/oyeong011.cpp b/valid-anagram/oyeong011.cpp index 905dd6f8e..64fca8a40 100644 --- a/valid-anagram/oyeong011.cpp +++ b/valid-anagram/oyeong011.cpp @@ -12,4 +12,4 @@ class Solution { // 문자열 비교 unordered_map은 해쉬 형태이므로 O(1) // 각 문자 루프 O(n) // 마지막 문자 비교 해시멥 알파벳은 26개 이므로 O(n) -// 따라서 O(n) \ No newline at end of file +// 따라서 O(n) From bfa66f6d0a080e33524151eece7c144d73ab37c1 Mon Sep 17 00:00:00 2001 From: oyeong011 Date: Tue, 17 Dec 2024 17:28:24 +0900 Subject: [PATCH 5/5] Climbing stairs sol --- climbing-stairs/oyeong011.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 climbing-stairs/oyeong011.cpp diff --git a/climbing-stairs/oyeong011.cpp b/climbing-stairs/oyeong011.cpp new file mode 100644 index 000000000..a65cf706f --- /dev/null +++ b/climbing-stairs/oyeong011.cpp @@ -0,0 +1,25 @@ +class Solution { +public: + int climbStairs(int n) { + if(n == 0 || n == 1){ + return 1; + } + vector 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)