feat: populate note files with problem descriptions and code stubs
Add populate-notes.mjs that fetches problem descriptions and Python/C++ code stubs from LeetCode's GraphQL API. Populated all 197 NeetCode 150 note files with: - Problem description (examples, constraints) - Python code stub (function signature) - C++ code stub (function signature + includes) API responses cached in leetcode/.cache/leetcode/ for instant re-runs.
This commit is contained in:
+36
-3
@@ -1,18 +1,51 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0005. Longest Palindromic Substring :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0005. Longest Palindromic Substring][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0005. Longest Palindromic Substring][0005. Longest Palindromic Substring]]
|
||||
:END:
|
||||
|
||||
Given a string ~s~, return /the longest/ /palindromic/ /substring/ in ~s~.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "babad"
|
||||
Output: "bab"
|
||||
Explanation: "aba" is also a valid answer.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "cbbd"
|
||||
Output: "bb"
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 1000~
|
||||
|
||||
- ~s~ consist of only digits and English letters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def longestPalindrome(self, s: str) -> str:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
string longestPalindrome(string s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,57 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0070. Climbing Stairs :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0070. Climbing Stairs][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0070. Climbing Stairs][0070. Climbing Stairs]]
|
||||
:END:
|
||||
|
||||
You are climbing a staircase. It takes ~n~ steps to reach the top.
|
||||
|
||||
Each time you can either climb ~1~ or ~2~ steps. In how many distinct ways can you climb to the top?
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: n = 2
|
||||
Output: 2
|
||||
Explanation: There are two ways to climb to the top.
|
||||
1. 1 step + 1 step
|
||||
2. 2 steps
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: n = 3
|
||||
Output: 3
|
||||
Explanation: There are three ways to climb to the top.
|
||||
1. 1 step + 1 step + 1 step
|
||||
2. 1 step + 2 steps
|
||||
3. 2 steps + 1 step
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= n <= 45~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def climbStairs(self, n: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int climbStairs(int n) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,88 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0091. Decode Ways :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0091. Decode Ways][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0091. Decode Ways][0091. Decode Ways]]
|
||||
:END:
|
||||
|
||||
You have intercepted a secret message encoded as a string of numbers. The message is *decoded* via the following mapping:
|
||||
|
||||
~"1" -> 'A'
|
||||
|
||||
"2" -> 'B'
|
||||
|
||||
...
|
||||
|
||||
"25" -> 'Y'
|
||||
|
||||
"26" -> 'Z'~
|
||||
|
||||
However, while decoding the message, you realize that there are many different ways you can decode the message because some codes are contained in other codes (~"2"~ and ~"5"~ vs ~"25"~).
|
||||
|
||||
For example, ~"11106"~ can be decoded into:
|
||||
|
||||
- ~"AAJF"~ with the grouping ~(1, 1, 10, 6)~
|
||||
|
||||
- ~"KJF"~ with the grouping ~(11, 10, 6)~
|
||||
|
||||
- The grouping ~(1, 11, 06)~ is invalid because ~"06"~ is not a valid code (only ~"6"~ is valid).
|
||||
|
||||
Note: there may be strings that are impossible to decode.
|
||||
|
||||
Given a string s containing only digits, return the *number of ways* to *decode* it. If the entire string cannot be decoded in any valid way, return ~0~.
|
||||
|
||||
The test cases are generated so that the answer fits in a *32-bit* integer.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
*Input:* s = "12"
|
||||
|
||||
*Output:* 2
|
||||
|
||||
*Explanation:*
|
||||
|
||||
"12" could be decoded as "AB" (1 2) or "L" (12).
|
||||
|
||||
*Example 2:*
|
||||
|
||||
*Input:* s = "226"
|
||||
|
||||
*Output:* 3
|
||||
|
||||
*Explanation:*
|
||||
|
||||
"226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
|
||||
|
||||
*Example 3:*
|
||||
|
||||
*Input:* s = "06"
|
||||
|
||||
*Output:* 0
|
||||
|
||||
*Explanation:*
|
||||
|
||||
"06" cannot be mapped to "F" because of the leading zero ("6" is different from "06"). In this case, the string is not a valid encoding, so return 0.
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 100~
|
||||
|
||||
- ~s~ contains only digits and may contain leading zero(s).
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def numDecodings(self, s: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int numDecodings(string s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,70 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0139. Word Break :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0139. Word Break][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0139. Word Break][0139. Word Break]]
|
||||
:END:
|
||||
|
||||
Given a string ~s~ and a dictionary of strings ~wordDict~, return ~true~ if ~s~ can be segmented into a space-separated sequence of one or more dictionary words.
|
||||
|
||||
*Note* that the same word in the dictionary may be reused multiple times in the segmentation.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "leetcode", wordDict = ["leet","code"]
|
||||
Output: true
|
||||
Explanation: Return true because "leetcode" can be segmented as "leet code".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "applepenapple", wordDict = ["apple","pen"]
|
||||
Output: true
|
||||
Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
|
||||
Note that you are allowed to reuse a dictionary word.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "catsandog", wordDict = ["cats","dog","sand","and","cat"]
|
||||
Output: false
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 300~
|
||||
|
||||
- ~1 <= wordDict.length <= 1000~
|
||||
|
||||
- ~1 <= wordDict[i].length <= 20~
|
||||
|
||||
- ~s~ and ~wordDict[i]~ consist of only lowercase English letters.
|
||||
|
||||
- All the strings of ~wordDict~ are *unique*.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool wordBreak(string s, vector<string>& wordDict) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,58 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0152. Maximum Product Subarray :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0152. Maximum Product Subarray][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0152. Maximum Product Subarray][0152. Maximum Product Subarray]]
|
||||
:END:
|
||||
|
||||
Given an integer array ~nums~, find a subarray that has the largest product, and return /the product/.
|
||||
|
||||
The test cases are generated so that the answer will fit in a *32-bit* integer.
|
||||
|
||||
*Note* that the product of an array with a single element is the value of that element.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [2,3,-2,4]
|
||||
Output: 6
|
||||
Explanation: [2,3] has the largest product 6.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [-2,0,-1]
|
||||
Output: 0
|
||||
Explanation: The result cannot be 2, because [-2,-1] is not a subarray.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 2 * 10^{4}~
|
||||
|
||||
- ~-10 <= nums[i] <= 10~
|
||||
|
||||
- The product of any subarray of ~nums~ is *guaranteed* to fit in a *32-bit* integer.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def maxProduct(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int maxProduct(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,56 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0198. House Robber :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0198. House Robber][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0198. House Robber][0198. House Robber]]
|
||||
:END:
|
||||
|
||||
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
|
||||
|
||||
Given an integer array ~nums~ representing the amount of money of each house, return /the maximum amount of money you can rob tonight without alerting the police/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,2,3,1]
|
||||
Output: 4
|
||||
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
|
||||
Total amount you can rob = 1 + 3 = 4.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [2,7,9,3,1]
|
||||
Output: 12
|
||||
Explanation: Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).
|
||||
Total amount you can rob = 2 + 9 + 1 = 12.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 100~
|
||||
|
||||
- ~0 <= nums[i] <= 400~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def rob(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int rob(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,64 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0213. House Robber II :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0213. House Robber II][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0213. House Robber II][0213. House Robber II]]
|
||||
:END:
|
||||
|
||||
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are *arranged in a circle.* That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.
|
||||
|
||||
Given an integer array ~nums~ representing the amount of money of each house, return /the maximum amount of money you can rob tonight *without alerting the police*/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [2,3,2]
|
||||
Output: 3
|
||||
Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,2,3,1]
|
||||
Output: 4
|
||||
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
|
||||
Total amount you can rob = 1 + 3 = 4.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,2,3]
|
||||
Output: 3
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 100~
|
||||
|
||||
- ~0 <= nums[i] <= 1000~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def rob(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int rob(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
+47
-3
@@ -1,18 +1,62 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0300. Longest Increasing Subsequence :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0300. Longest Increasing Subsequence][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0300. Longest Increasing Subsequence][0300. Longest Increasing Subsequence]]
|
||||
:END:
|
||||
|
||||
Given an integer array ~nums~, return /the length of the longest *strictly increasing *//*subsequence*/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [10,9,2,5,3,7,101,18]
|
||||
Output: 4
|
||||
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [0,1,0,3,2,3]
|
||||
Output: 4
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [7,7,7,7,7,7,7]
|
||||
Output: 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 2500~
|
||||
|
||||
- ~-10^{4} <= nums[i] <= 10^{4}~
|
||||
|
||||
Follow up: Can you come up with an algorithm that runs in ~O(n log(n))~ time complexity?
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def lengthOfLIS(self, nums: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int lengthOfLIS(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,66 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0322. Coin Change :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0322. Coin Change][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0322. Coin Change][0322. Coin Change]]
|
||||
:END:
|
||||
|
||||
You are given an integer array ~coins~ representing coins of different denominations and an integer ~amount~ representing a total amount of money.
|
||||
|
||||
Return /the fewest number of coins that you need to make up that amount/. If that amount of money cannot be made up by any combination of the coins, return ~-1~.
|
||||
|
||||
You may assume that you have an infinite number of each kind of coin.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: coins = [1,2,5], amount = 11
|
||||
Output: 3
|
||||
Explanation: 11 = 5 + 5 + 1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: coins = [2], amount = 3
|
||||
Output: -1
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 3:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: coins = [1], amount = 0
|
||||
Output: 0
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= coins.length <= 12~
|
||||
|
||||
- ~1 <= coins[i] <= 2^{31} - 1~
|
||||
|
||||
- ~0 <= amount <= 10^{4}~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def coinChange(self, coins: List[int], amount: int) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int coinChange(vector<int>& coins, int amount) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,52 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0416. Partition Equal Subset Sum :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0416. Partition Equal Subset Sum][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0416. Partition Equal Subset Sum][0416. Partition Equal Subset Sum]]
|
||||
:END:
|
||||
|
||||
Given an integer array ~nums~, return ~true~ /if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or /~false~/ otherwise/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,5,11,5]
|
||||
Output: true
|
||||
Explanation: The array can be partitioned as [1, 5, 5] and [11].
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: nums = [1,2,3,5]
|
||||
Output: false
|
||||
Explanation: The array cannot be partitioned into equal sum subsets.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= nums.length <= 200~
|
||||
|
||||
- ~1 <= nums[i] <= 100~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def canPartition(self, nums: List[int]) -> bool:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
bool canPartition(vector<int>& nums) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,18 +1,56 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0647. Palindromic Substrings :medium:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0647. Palindromic Substrings][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0647. Palindromic Substrings][0647. Palindromic Substrings]]
|
||||
:END:
|
||||
|
||||
Given a string ~s~, return /the number of *palindromic substrings* in it/.
|
||||
|
||||
A string is a *palindrome* when it reads the same backward as forward.
|
||||
|
||||
A *substring* is a contiguous sequence of characters within the string.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "abc"
|
||||
Output: 3
|
||||
Explanation: Three palindromic strings: "a", "b", "c".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: s = "aaa"
|
||||
Output: 6
|
||||
Explanation: Six palindromic strings: "a", "a", "a", "aa", "aa", "aaa".
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~1 <= s.length <= 1000~
|
||||
|
||||
- ~s~ consists of lowercase English letters.
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def countSubstrings(self, s: str) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int countSubstrings(string s) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0656. Coin Path :hard:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0656. Coin Path][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0656. Coin Path][0656. Coin Path]]
|
||||
:END:
|
||||
|
||||
** TODO Approach
|
||||
|
||||
@@ -1,18 +1,65 @@
|
||||
#+PROPERTY: STUDY_DECK_02
|
||||
* TODO 0746. Min Cost Climbing Stairs :easy:
|
||||
:PROPERTIES:
|
||||
:NEETCODE: [[file:../../roadmap.org::*0746. Min Cost Climbing Stairs][Roadmap]]
|
||||
:NEETCODE: [[file:../../roadmap.org::*0746. Min Cost Climbing Stairs][0746. Min Cost Climbing Stairs]]
|
||||
:END:
|
||||
|
||||
You are given an integer array ~cost~ where ~cost[i]~ is the cost of ~i^{th}~ step on a staircase. Once you pay the cost, you can either climb one or two steps.
|
||||
|
||||
You can either start from the step with index ~0~, or the step with index ~1~.
|
||||
|
||||
Return /the minimum cost to reach the top of the floor/.
|
||||
|
||||
*Example 1:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: cost = [10,15,20]
|
||||
Output: 15
|
||||
Explanation: You will start at index 1.
|
||||
- Pay 15 and climb two steps to reach the top.
|
||||
The total cost is 15.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Example 2:*
|
||||
|
||||
|
||||
#+begin_src
|
||||
Input: cost = [1,100,1,1,1,100,1,1,100,1]
|
||||
Output: 6
|
||||
Explanation: You will start at index 0.
|
||||
- Pay 1 and climb two steps to reach index 2.
|
||||
- Pay 1 and climb two steps to reach index 4.
|
||||
- Pay 1 and climb two steps to reach index 6.
|
||||
- Pay 1 and climb one step to reach index 7.
|
||||
- Pay 1 and climb two steps to reach index 9.
|
||||
- Pay 1 and climb one step to reach the top.
|
||||
The total cost is 6.
|
||||
#+end_src
|
||||
|
||||
|
||||
*Constraints:*
|
||||
|
||||
- ~2 <= cost.length <= 1000~
|
||||
|
||||
- ~0 <= cost[i] <= 999~
|
||||
|
||||
** TODO Approach
|
||||
Write your approach here.
|
||||
|
||||
** TODO Python
|
||||
#+begin_src python
|
||||
|
||||
class Solution:
|
||||
def minCostClimbingStairs(self, cost: List[int]) -> int:
|
||||
#+end_src
|
||||
|
||||
** TODO C++
|
||||
#+begin_src cpp
|
||||
|
||||
class Solution {
|
||||
public:
|
||||
int minCostClimbingStairs(vector<int>& cost) {
|
||||
|
||||
}
|
||||
};
|
||||
#+end_src
|
||||
|
||||
Reference in New Issue
Block a user