본문 바로가기

다이나믹프로그래밍26

[leetcode 96] Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that store values 1 ... n? 1부터 n까지 사용하여 만들 수 있는 bst 경우의 수 Example: Input: 3 Output: 5 Explanation: Given n = 3, there are a total of 5 unique BST's: Constraints: 1 2020. 10. 26.
[leetcode 139] Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. wordDict에 있는 단어들로 주어진 s를 빠짐없이 분리할 수 있는가 Note: The same word in the dictionary may be reused multiple times in the segmentation. You may assume the dictionary does not contain duplicate words. Example 1: Input: .. 2020. 10. 26.
[leetcode 70] Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 계단을 1 혹은 2개씩 오를 수 있을 때 목표지점까지 도달할 수 있는 방법? Example 1: Input: 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: 3 Output: 3 Explanation: There are three ways to climb to .. 2020. 10. 26.
[leetcode 152] Maximum Product Subarray Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product. 연속 곱중에 가장 큰 곱을 리턴하라. Example 1: Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Example 2: Input: [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1] is not a subarray. 풀이: - dp이자 그리디 스러운 문제이다. - 음수가 있어서 어려웠던 문제! .. 2020. 10. 26.