Algorithm
-
[Leetcode] 120. Triangle 문제풀이Algorithm/문제풀이 2021. 9. 12. 15:45
https://leetcode.com/problems/triangle/ Triangle - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 삼각형 배열에서 탑에서 바닥까지 경로를 구할 때 경로의 합이 최소인 값을 구하는 문제 경로는 i, i + 1칸 움직일 수 있다. Example 1: Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] Output: 11 Explanation: The triangle looks lik..
-
[Leetcode] 198. House Robber 문제풀이Algorithm/문제풀이 2021. 9. 10. 19:54
https://leetcode.com/problems/house-robber/ House Robber - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 도둑질 하는데 인접한 집은 할 수 없다. 주어진 배열은 집의 돈이라고 볼 수 있고 클수록 좋다. 가장 많이 돈을 벌 수 있는 값을 찾는 문제 Example 1: Input: nums = [1,2,3,1] Output: 4 Explanation: Rob house 1 (money = 1) and then..
-
[Leetcode] 70. Climbing Stairs 문제풀이Algorithm/문제풀이 2021. 9. 10. 19:44
https://leetcode.com/problems/climbing-stairs/ Climbing Stairs - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 1칸 또는 2칸을 갈 수 있는데 도착할때 까지 가능한 모든 경우의 수 구하는 문제 Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps ..
-
[Leetcode] 764. Largest Plus Sign 문제 풀이Algorithm/문제풀이 2021. 9. 10. 00:12
https://leetcode.com/problems/largest-plus-sign/ Largest Plus Sign - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 맵에서 plus + 모양의 길이가 최대인 값을 구하는 문제 길이는 폭탄을 제외한 거리이다. 문제 풀이 일반적으로 풀면 모든 점을 탐색하고 4방향으로 탐색하면 N^3 만큼의 시간이 걸린다. dp를 사용해서 4방향의 값을 미리 알고 있다면 탐색하는 시간인 N^2만큼 걸린다. class S..
-
[Leetcode] 77. Combinations 문제 풀이Algorithm/문제풀이 2021. 9. 9. 22:47
https://leetcode.com/problems/combinations/ Combinations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 n개 중에서 k개로 조합할 수 있는 모든 수를 구하는 문제 Example 1: Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] 문제 풀이 divide & conquer 방식으로 풀었다. s부터 e 까지의 숫자가 있을 때..
-
[Leetcode] 46. Permutations 문제 풀이Algorithm/문제풀이 2021. 9. 9. 22:43
https://leetcode.com/problems/permutations/ Permutations - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 주어진 숫자 배열에서 모든 조합을 구하는 문제 Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] 문제 풀이 divide & conquer 방식으로 풀었다. N개의 길이가 있을 때, N개의 모..
-
[Leetcode] 784. Letter Case Permutation 문제 풀이Algorithm/문제풀이 2021. 9. 9. 22:37
https://leetcode.com/problems/letter-case-permutation/ Letter Case Permutation - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 문자열이 주어지는 데 문자가 대문자일 경우, 소문자일 경우를 모두 찾는 문제 Example 1: Input: s = "a1b2" Output: ["a1b2","a1B2","A1b2","A1B2"] 문제 풀이 경우의 수를 모두 하면 된다. 2가지의 경우가 있다. i..
-
[LeetCode] 21. Merge Two Sorted Lists 문제풀이Algorithm/문제풀이 2021. 9. 8. 23:09
https://leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문제 내용 링크드 리스트 2개를 정렬된 하나의 링크드 리스트로 출력하기 문제 풀이 크기를 비교해서 하나씩 next로 연결해주면 된다 class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { if..