분류 전체보기
-
[LeetCode] 1387. Sort Integers by The Power Value알고리즘 문제 풀이 2021. 5. 7. 16:25
출처: https://leetcode.com/problems/sort-integers-by-the-power-value/ Sort Integers by The Power Value - 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 문제 정수 x의 힘(power)는 다음 규칙을 따라 x를 1로 바꾸는데 필요한 단계의 수로 정의한다. 만약 x가 짝수라면 x = x / 2 만약 x가 홀수라면 x = 3 * x + 1 예를 들어, x = 3의 힘은 3이 1이 되는데 7..
-
[LeetCode] 845. Longest Mountain in Array알고리즘 문제 풀이 2021. 5. 6. 16:34
출처: https://leetcode.com/problems/longest-mountain-in-array/ Longest Mountain in 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 문제 배열 arr이 다음과 같을 때 산 배열이라 할 수 있다: arr.length >= 3 0 arr[i..
-
[LeetCode] 191. Number of 1 Bits알고리즘 문제 풀이 2021. 5. 4. 12:27
출처: leetcode.com/problems/number-of-1-bits/ Number of 1 Bits - 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'비트의 수를 반환하라(Hamming weight를 계산하라). 예제 Input: n = 00000000000000000000000000001011 Output: 3 Explanation: The input binary string 00000000000000000000..
-
[LeetCode] 780. Reaching Points알고리즘 문제 풀이 2021. 5. 3. 14:12
출처: leetcode.com/problems/reaching-points/ Reaching Points - 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 문제 한번의 이동은 좌표 (x, y)에서 (x, x+y) 또는 (x+y, y)로의 변화로 구성된다. 시작 좌표 (sx, sy)와 목표 좌표 (tx, ty)가 주어지면, 좌표 (sx, sy)에서 (tx, ty)로 이동할 수 있다면 True를 반환한다. 그렇지 않다면 False를 반환한다. 단, sx, sy, t..
-
[LeetCode] 910. Smallest Range II알고리즘 문제 풀이 2021. 4. 30. 12:32
출처: https://leetcode.com/problems/smallest-range-ii/ 문제 정수 배열 A에서, 모든 A[i]에 -K 또는 K를 선택하여 더한다(오직 한번). 이 과정 후의 배열을 B라 하자. 배열 B의 원소 중 가장 큰 값과 작은 값의 차이가 가장 작을 때의 차를 반환하라. 예제 Input: A[0,10], K = 2 Ouput: 6 Explanation: B = [2,8] Input: A = [1,3,6], K = 3 Output: 3 Explanation: B = [4,6,3] 풀이 우선, 배열의 최솟값, 최댓값을 쉽게 파악하기 위해서 입력으로 주어지는 배열 A를 오름차순으로 정렬한다. 이 상태에서 배열의 최댓값 - 최솟값의 크기를 줄이기 위해서 최댓값 - K, 최솟값 + K..