IN DEPTH CAKE
-
λμ΄λ: Mediumν€μλ: DP π λ¬Έμ μνλ²³ A-Zμ λ¬Έμλ‘ μ΄λ£¨μ΄μ§ λ©μμ§λ λ€μ 맀νμ μ¬μ©νμ¬ μ«μλ‘ μΈμ½λ©λ μ μμ΅λλ€:'A' -> "1"'B' -> "2"...'Z' -> "26" μΈμ½λ©λ λ©μμ§λ₯Ό λμ½λ©νλ €λ©΄, λͺ¨λ μ«μλ₯Ό κ·Έλ£Ήννκ³ μμ 맀νμ λ°λλ‘ μ¬μ©νμ¬ λ€μ λ¬Έμλ‘ λ§€νν΄μΌ ν©λλ€ (μ¬λ¬ λ°©λ²μ΄ μμ μ μμ). μλ₯Ό λ€μ΄, "11106"μ λ€μκ³Ό κ°μ΄ 맀νλ μ μμ΅λλ€:(1 1 10 6)μ κ·Έλ£Ήννμ¬ "AAJF"(11 10 6)μ κ·Έλ£Ήννμ¬ "KJF"(1 11 06)μ κ·Έλ£Ήννλ κ²μ "06"μ 'F'λ‘ λ§€νν μ μμΌλ―λ‘ μλͺ»λ κ²μμ μ μνμΈμ.μ«μλ§ ν¬ν¨νλ λ¬Έμμ΄ sκ° μ£Όμ΄μ‘μ λ, μ΄λ₯Ό λμ½λ©νλ λ°©λ²μ μλ₯Ό λ°ννμΈμ.ν μ€νΈ μΌμ΄μ€λ λ΅μ΄ 32λΉνΈ μ μμ λ§λ..
[c++/LeetCode-DP] 91. Decode Ways (w/ DP νμ΄ μ λ΅)λμ΄λ: Mediumν€μλ: DP π λ¬Έμ μνλ²³ A-Zμ λ¬Έμλ‘ μ΄λ£¨μ΄μ§ λ©μμ§λ λ€μ 맀νμ μ¬μ©νμ¬ μ«μλ‘ μΈμ½λ©λ μ μμ΅λλ€:'A' -> "1"'B' -> "2"...'Z' -> "26" μΈμ½λ©λ λ©μμ§λ₯Ό λμ½λ©νλ €λ©΄, λͺ¨λ μ«μλ₯Ό κ·Έλ£Ήννκ³ μμ 맀νμ λ°λλ‘ μ¬μ©νμ¬ λ€μ λ¬Έμλ‘ λ§€νν΄μΌ ν©λλ€ (μ¬λ¬ λ°©λ²μ΄ μμ μ μμ). μλ₯Ό λ€μ΄, "11106"μ λ€μκ³Ό κ°μ΄ 맀νλ μ μμ΅λλ€:(1 1 10 6)μ κ·Έλ£Ήννμ¬ "AAJF"(11 10 6)μ κ·Έλ£Ήννμ¬ "KJF"(1 11 06)μ κ·Έλ£Ήννλ κ²μ "06"μ 'F'λ‘ λ§€νν μ μμΌλ―λ‘ μλͺ»λ κ²μμ μ μνμΈμ.μ«μλ§ ν¬ν¨νλ λ¬Έμμ΄ sκ° μ£Όμ΄μ‘μ λ, μ΄λ₯Ό λμ½λ©νλ λ°©λ²μ μλ₯Ό λ°ννμΈμ.ν μ€νΈ μΌμ΄μ€λ λ΅μ΄ 32λΉνΈ μ μμ λ§λ..
2024.05.06 -
λμ΄λ: Easyν€μλ: DP π λ¬Έμ μ μ λ°°μ΄ costκ° μ£Όμ΄μ§λ©°, cost[i]λ κ³λ¨μ iλ²μ§Έ λ¨κ³μ λΉμ©μ λλ€. λΉμ©μ μ§λΆνλ©΄ 1κ° λλ 2κ°μ λ¨κ³λ₯Ό μ€λ₯Ό μ μμ΅λλ€.μΈλ±μ€ 0 λλ μΈλ±μ€ 1μ λ¨κ³μμ μμν μ μμ΅λλ€.μ΅μμ μΈ΅μ λλ¬νκΈ° μν μ΅μ λΉμ©μ λ°ννμΈμ. Example 1:Input: cost = [10,15,20]Output: 15Explanation: You will start at index 1.- Pay 15 and climb two steps to reach the top.The total cost is 15. Example 2:Input: cost = [1,100,1,1,1,100,1,1,100,1]Output: 6Explanation: You will..
[c++/LeetCode-DP] 746. Min Cost Climbing Stairsλμ΄λ: Easyν€μλ: DP π λ¬Έμ μ μ λ°°μ΄ costκ° μ£Όμ΄μ§λ©°, cost[i]λ κ³λ¨μ iλ²μ§Έ λ¨κ³μ λΉμ©μ λλ€. λΉμ©μ μ§λΆνλ©΄ 1κ° λλ 2κ°μ λ¨κ³λ₯Ό μ€λ₯Ό μ μμ΅λλ€.μΈλ±μ€ 0 λλ μΈλ±μ€ 1μ λ¨κ³μμ μμν μ μμ΅λλ€.μ΅μμ μΈ΅μ λλ¬νκΈ° μν μ΅μ λΉμ©μ λ°ννμΈμ. Example 1:Input: cost = [10,15,20]Output: 15Explanation: You will start at index 1.- Pay 15 and climb two steps to reach the top.The total cost is 15. Example 2:Input: cost = [1,100,1,1,1,100,1,1,100,1]Output: 6Explanation: You will..
2024.05.06 -
λμ΄λ: Easyν€μλ: DP π λ¬Έμ κ³λ¨μ μ€λ₯΄κ³ μμ΅λλ€. κΌλκΈ°μ λλ¬νκΈ° μν΄ nκ°μ λ¨κ³κ° νμν©λλ€.κ° λ¨κ³λ§λ€ 1κ° λλ 2κ°μ λ¨κ³λ₯Ό μ€λ₯Ό μ μμ΅λλ€. κΌλκΈ°μ λλ¬νλ λ° λͺ κ°μ§ λ€λ₯Έ λ°©λ²μ΄ μλμ§ κ³μ°νμΈμ. Example 1:Input: n = 2Output: 2Explanation: There are two ways to climb to the top.1. 1 step + 1 step2. 2 steps Example 2:Input: n = 3Output: 3Explanation: There are three ways to climb to the top.1. 1 step + 1 step + 1 step2. 1 step + 2 steps3. 2 steps + 1 step λ¬Έ..
[c++/LeetCode-DP] 70. Climbing Stairsλμ΄λ: Easyν€μλ: DP π λ¬Έμ κ³λ¨μ μ€λ₯΄κ³ μμ΅λλ€. κΌλκΈ°μ λλ¬νκΈ° μν΄ nκ°μ λ¨κ³κ° νμν©λλ€.κ° λ¨κ³λ§λ€ 1κ° λλ 2κ°μ λ¨κ³λ₯Ό μ€λ₯Ό μ μμ΅λλ€. κΌλκΈ°μ λλ¬νλ λ° λͺ κ°μ§ λ€λ₯Έ λ°©λ²μ΄ μλμ§ κ³μ°νμΈμ. Example 1:Input: n = 2Output: 2Explanation: There are two ways to climb to the top.1. 1 step + 1 step2. 2 steps Example 2:Input: n = 3Output: 3Explanation: There are three ways to climb to the top.1. 1 step + 1 step + 1 step2. 1 step + 2 steps3. 2 steps + 1 step λ¬Έ..
2024.05.06 -
λμ΄λ: Mediumν€μλ: Hash Table π² λ¬Έμ X-Y νλ©΄μμ μ λ€μ λ°°μ΄ pointsκ° μ£Όμ΄μ‘μ΅λλ€. μ¬κΈ°μ points[i] = [xi, yi]μ λλ€.μ΄λ¬ν μ λ€λ‘ νμ±λ XμΆκ³Ό YμΆμ ννν μ§μ¬κ°νμ μ΅μ λ©΄μ μ λ°νν©λλ€. λ§μ½ κ·Έλ¬ν μ§μ¬κ°νμ΄ μλ€λ©΄, 0μ λ°νν©λλ€. λ¬Έμ μλ¬Έ: https://leetcode.com/problems/minimum-area-rectangle/description/ Example 1:Input: points = [[1,1],[1,3],[3,1],[3,3],[2,2]]Output: 4 π² λ¬Έμ νμ΄λ§λ€ μ μλ μ¬κ°νμ νμνλ©΄μ μ¬κ°νλ€ μ€ μ΅μ λ©΄μ κ°μ ꡬνκ³ μνλ€.μ΄λ₯Ό μν΄μ λ κ°μ μ μ΄ μ£Όμ΄μ‘μ λ μ΄ λ μ μΈμ μ¬κ°νμ λ§λ€ μ ..
[c++/LeetCode-Hash Table] 939. Minimum Area Rectangleλμ΄λ: Mediumν€μλ: Hash Table π² λ¬Έμ X-Y νλ©΄μμ μ λ€μ λ°°μ΄ pointsκ° μ£Όμ΄μ‘μ΅λλ€. μ¬κΈ°μ points[i] = [xi, yi]μ λλ€.μ΄λ¬ν μ λ€λ‘ νμ±λ XμΆκ³Ό YμΆμ ννν μ§μ¬κ°νμ μ΅μ λ©΄μ μ λ°νν©λλ€. λ§μ½ κ·Έλ¬ν μ§μ¬κ°νμ΄ μλ€λ©΄, 0μ λ°νν©λλ€. λ¬Έμ μλ¬Έ: https://leetcode.com/problems/minimum-area-rectangle/description/ Example 1:Input: points = [[1,1],[1,3],[3,1],[3,3],[2,2]]Output: 4 π² λ¬Έμ νμ΄λ§λ€ μ μλ μ¬κ°νμ νμνλ©΄μ μ¬κ°νλ€ μ€ μ΅μ λ©΄μ κ°μ ꡬνκ³ μνλ€.μ΄λ₯Ό μν΄μ λ κ°μ μ μ΄ μ£Όμ΄μ‘μ λ μ΄ λ μ μΈμ μ¬κ°νμ λ§λ€ μ ..
2024.05.05 -
λμ΄λ: Mediumν€μλ: Hash Table π² λ¬Έμ λ¬Έμμ΄ λ°°μ΄ wordsμ μ μ kκ° μ£Όμ΄μ‘μ λ, kκ°μ κ°μ₯ λΉλ²ν λ¬Έμμ΄μ λ°νν©λλ€.λΉλμκ° λμ μμλλ‘ μ λ ¬λ λ΅μ λ°νν©λλ€. λμΌν λΉλλ₯Ό κ°μ§ λ¬Έμμ΄μ μ¬μ μμΌλ‘ μ λ ¬ν©λλ€. π² μμExample 1:Input: words = ["i","love","leetcode","i","love","coding"], k = 2Output: ["i","love"]Explanation: "i" and "love" are the two most frequent words.Note that "i" comes before "love" due to a lower alphabetical order. Example 2:Input: words = ["th..
[c++/LeetCode-Hash Table] 692. Top K Frequent Wordsλμ΄λ: Mediumν€μλ: Hash Table π² λ¬Έμ λ¬Έμμ΄ λ°°μ΄ wordsμ μ μ kκ° μ£Όμ΄μ‘μ λ, kκ°μ κ°μ₯ λΉλ²ν λ¬Έμμ΄μ λ°νν©λλ€.λΉλμκ° λμ μμλλ‘ μ λ ¬λ λ΅μ λ°νν©λλ€. λμΌν λΉλλ₯Ό κ°μ§ λ¬Έμμ΄μ μ¬μ μμΌλ‘ μ λ ¬ν©λλ€. π² μμExample 1:Input: words = ["i","love","leetcode","i","love","coding"], k = 2Output: ["i","love"]Explanation: "i" and "love" are the two most frequent words.Note that "i" comes before "love" due to a lower alphabetical order. Example 2:Input: words = ["th..
2024.05.05 -
λμ΄λ: Easyν€μλ: Stack λ¬Έμ λ¬Έμμ΄ sκ° μ£Όμ΄μ‘μ λ, 첫 λ²μ§Έλ‘ λ°λ³΅λμ§ μλ λ¬Έμλ₯Ό μ°Ύκ³ κ·Έ μΈλ±μ€λ₯Ό λ°νν©λλ€. λ§μ½ κ·Έλ° λ¬Έμκ° μλ€λ©΄, -1μ λ°νν©λλ€. μ μΆλ ₯ μμ Example 1:Input: s = "leetcode"Output: 0 Example 2:Input: s = "loveleetcode"Output: 2 Example 3:Input: s = "aabb"Output: -1 λ¬Έμ νμ΄class Solution {public: int firstUniqChar(string s) { unordered_map hash; for(const auto c : s){ const auto ptr = hash.find(c); ..
[c++/LeetCode-Hash Table] 387. First Unique Character in a Stringλμ΄λ: Easyν€μλ: Stack λ¬Έμ λ¬Έμμ΄ sκ° μ£Όμ΄μ‘μ λ, 첫 λ²μ§Έλ‘ λ°λ³΅λμ§ μλ λ¬Έμλ₯Ό μ°Ύκ³ κ·Έ μΈλ±μ€λ₯Ό λ°νν©λλ€. λ§μ½ κ·Έλ° λ¬Έμκ° μλ€λ©΄, -1μ λ°νν©λλ€. μ μΆλ ₯ μμ Example 1:Input: s = "leetcode"Output: 0 Example 2:Input: s = "loveleetcode"Output: 2 Example 3:Input: s = "aabb"Output: -1 λ¬Έμ νμ΄class Solution {public: int firstUniqChar(string s) { unordered_map hash; for(const auto c : s){ const auto ptr = hash.find(c); ..
2024.05.05