본문 바로가기

동적프로그래밍12

C++ 287. Find the Duplicate Number(Leet Code) Leet Code_287. Find the Duplicate Number https://leetcode.com/problems/find-the-duplicate-number/ 문제 해석 이 문제를 풀기위해 이해해야 할 내용은 다음과 같습니다. 목표 배열안의 중복된 숫자 찾기 ​ 방법 1. 배열안의 중복된 숫자 찾기 결과 배열안의 중복된 숫자 찾기 통과한 코드 class Solution { public: int findDuplicate(vector& nums) { std::map m; std::map::iterator it; for(int i = 0 ; i < nums.size() ; i++) { it = m.find(nums[i]); if (it == m.end()) { m.insert ( std::pa.. 2020. 6. 18.
C++ 64. Minimum Path Sum(Leet Code) Leet Code_64. Minimum Path Sum Dynamic Programming https://leetcode.com/problems/minimum-path-sum/ 문제 해석 이 문제를 풀기위해 이해해야 할 내용은 다음과 같습니다. 목표 Start부터 Finish 까지 갈수있는 경로중 가장 적은 비용이 드는 경로의 비용 구하기 ​ 방법 1. Start부터 Finish 까지 갈수있는 경로중 가장 적은 비용이 드는 경로의 비용 구하기 결과 Start부터 Finish 까지 갈수있는 경로중 가장 적은 비용이 드는 경로의 비용 구하기 통과한 코드 class Solution { public: int minPathSum(vector& grid) { vector vec = grid; int col = gr.. 2020. 6. 18.
C++ 62. Unique Paths(Leet Code) Leet Code_62. Unique Paths Dynamic Programming https://leetcode.com/problems/unique-paths/ 문제 해석 이 문제를 풀기위해 이해해야 할 내용은 다음과 같습니다. 목표 Start부터 Finish 까지 갈수있는 중복되지 않는 모든 경로 구하기 ​ 방법 1. Start부터 Finish 까지 갈수있는 중복되지 않는 모든 경로 구하기 결과 Start부터 Finish 까지 갈수있는 중복되지 않는 모든 경로 구하기 통과한 코드 class Solution { public: int uniquePaths(int m, int n) { if(n == 0 && m == 0) return 0; vector dp(n,vector(m,0)); dp[0][0] = .. 2020. 6. 18.
C++ 22. Generate Parentheses(Leet Code) Leet Code_22. Generate Parentheses Dynamic Programming https://leetcode.com/problems/generate-parentheses/ 문제 해석 이 문제를 풀기위해 이해해야 할 내용은 다음과 같습니다. 목표 n개의 괄호를 표현할 수 있는 모든 경우의 수를 만들기 ​ 방법 1. n개의 괄호를 표현할 수 있는 모든 경우의 수를 만들기 결과 n개의 괄호를 표현할 수 있는 모든 경우의 수를 만들기 통과한 코드 class Solution { public: vector generateParenthesis(int n) { vectorans; int tail=0,left=n,right=n,k=0; string s(n*2, 'a'); dfs(tail,left,ri.. 2020. 6. 16.