전체 글
-
[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..
-
[LeetCode] 848. Shifting Letters 문제풀이Algorithm/문제풀이 2021. 9. 8. 16:41
https://leetcode.com/problems/shifting-letters/ Shifting Letters - 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 문제 내용 문자를 shift 한 결과를 출력하는 문제 문제 풀이 어차피 다 shift 한 결과를 구하는 것이기 때문에 문자를 다 'a' 로 초기화 되있다고 생각하고 shift 값만 구하면 된다. class Solution { public: string shiftingLetters(string s, ..
-
[LeetCode] 206. Reverse Linked List 문제 풀이Algorithm/문제풀이 2021. 9. 8. 16:04
https://leetcode.com/problems/reverse-linked-list/ Reverse Linked List - 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 문제 내용 링크드 리스트를 거꾸로 출력하면 된다. 문제 풀이 3개의 변수를 두고 노드 방향을 뒤집고 한칸씩 땡기고 했다. class Solution { public: ListNode* reverseList(ListNode* head) { if (head == nullptr) return ..
-
[LeetCode] 994. Rotting Oranges 문제 풀이Algorithm/문제풀이 2021. 9. 8. 16:01
https://leetcode.com/problems/rotting-oranges/ Rotting Oranges - 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 문제 내용 썩은 귤이 있는데 4방향으로 인접해 있는 곳으로 퍼진다. 몇일 만에 남은 귤이 다 썩는지 출력하고 다 안썩으면 -1 출력하는 문제 문제 풀이 썩은 귤을 모두 Queue에 담고 하나씩 퍼져가면서 day를 구하면 된다. 그리고 마지막에 귤을 검사해서 멀쩡한 귤이 있으면 -1을 출력하면 된다. c..