전체 글
-
[LeetCode] 153. Find Minimum in Rotated Sorted Array 문제풀이Algorithm/문제풀이 2021. 9. 1. 21:25
https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated Sorted Array - 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 = [3,4,5,1,2] Output: 1 Explanation: The original array was [..
-
[LeetCode] 167. Two Sum II - Input array is sorted 문제풀이Algorithm/문제풀이 2021. 9. 1. 20:13
https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ Two Sum II - Input array is sorted - 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개의 합이 target이랑 일치할 때 배열의 index 2개를 출력 문제 풀이 두 숫자의 합을 구하는 것을 target을 뺀 다음에 바이너리 서치로 찾는 방법을 생각했다. class Solution { ..
-
[LeetCode] 283. Move Zeroes 문제풀이Algorithm/문제풀이 2021. 9. 1. 18:59
https://leetcode.com/problems/move-zeroes/ Move Zeroes - 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 문제 내용 배열에 0값이 섞여있는데 정렬상태를 유지하면서 0을 end쪽으로 몰아 넣는 문제 문제 풀이 index 2개로 swap하면 됐다. class Solution { public: void moveZeroes(vector& nums) { for (int i = 0, j = 0; i < nums.size(); ++..
-
[LeetCode] 977. Squares of a Sorted Array 문제풀이Algorithm/문제풀이 2021. 9. 1. 10:54
https://leetcode.com/problems/squares-of-a-sorted-array/ Squares of a Sorted Array - 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 = [-4,-1,0,3,10] Output: [0,1,9,16,100] Explanation: After squaring, the array become..
-
[LeetCode] Longest Uncommon Subsequence II 문제풀이Algorithm/문제풀이 2021. 8. 28. 14:01
https://leetcode.com/problems/longest-uncommon-subsequence-ii/ Longest Uncommon Subsequence II - 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 문제 내용 문자열 배열 중에 LCS가 하나도 없는 문자열 길이 중 최대 값 찾기 문제 풀이 Trie 이용해서 매칭으로 푸는 방법 문자열 부분 집합중에 공통된 것이 없으면 된다고 생각했다. 문자열에 대해 부분 집합을 모두 구하고, 문자열 매칭 자료..
-
[LeetCode] Verify Preorder Serialization of a Binary Tree 문제풀이Algorithm/문제풀이 2021. 8. 26. 21:15
https://leetcode.com/problems/verify-preorder-serialization-of-a-binary-tree/ Verify Preorder Serialization of a Binary Tree - 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 문제 설명 preorder된 입력 string이 주어지고 온전히 트리의 구성을 하고 있는 지 확인하는 문제이다. 문제 풀이 방법1. index 크기 검사 생각했을 때, preorder 로 탐색..
-
[LeetCode] Rectangle Area II 문제풀이Algorithm/문제풀이 2021. 8. 26. 19:12
https://leetcode.com/problems/rectangle-area-ii/ Rectangle Area II - 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 문제 내용 사각형이 좌표로 주어지는 데 총 면적을 구하는 것이다. 겹치는 것 제외하고 커버하는 것만 면적 구하는 것이다. 입력은 [x1 y1 x2 y2] 로 왼쪽밑하고 오른쪽위 좌표점이 주어진다. 2개의 좌표를 알면 사각형이 어떻게 생겼는 지 알 수 있다. 문제 풀이 겹치지 않으면 가로 * 세로..
-
[프로그래머스] 더 맵게 문제 풀이Algorithm/문제풀이 2021. 8. 22. 08:18
https://programmers.co.kr/learn/courses/30/lessons/42626# 코딩테스트 연습 - 더 맵게 매운 것을 좋아하는 Leo는 모든 음식의 스코빌 지수를 K 이상으로 만들고 싶습니다. 모든 음식의 스코빌 지수를 K 이상으로 만들기 위해 Leo는 스코빌 지수가 가장 낮은 두 개의 음식을 아래와 같 programmers.co.kr 최소값 2개를 꺼내서 연산을 반복해서 K 이상 만들 수 있는지 푸는 문제이다. 매번 최소값이 필요하기 때문에 최소값을 빠르게 구하는 방법이 중요하다. min heap을 사용하면 금방 풀 수 있다. c++ STL에서 priority_queue 를 사용하면 금방 풀 수 있지만, 직접 구현하는 것이 의미가 있다. priority_queue를 이용해서 간..