본문 바로가기

분류 전체보기351

[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.
[leetcode 198] House Robber 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 system connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given a list of non-negative integers representing the amount.. 2020. 10. 25.
[leetcode 39] Combination Sum Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order. The same number may be chosen from candidates an unlimited number of times. Two combinations are unique if the frequency of at least one of the chosen numbers is different. It is gu.. 2020. 10. 25.
[leetcode 105] Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree. preorder와 inorder 배열보고 본래 이진 트리 구현하기 Note: You may assume that duplicates do not exist in the tree. For example, given preorder = [3,9,20,15,7] inorder = [9,3,15,20,7] Return the following binary tree: 풀이: - 난이도는 medium이었지만 몹시 어려웠다. - dfs와 inorder preorder의 개념이 혼합된 문제 - 핵심 개념: inorder는 왼쪽 서브트리 -> 루트 -> 오른쪽 서브 트리 preorder는.. 2020. 10. 24.