807. Max Increase to Keep City Skyline
·
Algorithm
Max Increase to Keep City Skyline - 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차원 배열이 주어진다. 2차원 배열을 4방으로 보았을 때 생기는 등고선(skyline)을 유지하면서 최대로 올릴 수 있는 건물의 사이즈를 반환하는 문제다. 예를 들어서 [5,2]라는 1차원 배열을 왼쪽에서 바라보면 5만 보일 것이고, 2가 있는 자리에 3을 더해서 [5, 5]로 만들어도 보이는 모습은 같을 것이다. 이걸 2차원 배열의 경우로 생각할 때..
210. Course Schedule II
·
Algorithm
Course Schedule 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 이전에 풀었던 문제와 비슷하지만 이번에는 가능한 수강 순서 중 하나를 반환하는 문제다. 1. 위상 정렬 from typing import * from collections import defaultdict, deque class Solution: def findOrder(self, numCourses: int, prerequisites: List[List[int]]) -> Lis..
307. Range Sum Query - Mutable
·
Algorithm
Range Sum Query - Mutable - 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 정수로 이루어진 list가 주어질 때 주석으로 된 코드가 작동하도록 메서드를 구현하는 문제다. class NumArray: def __init__(self, nums: List[int]): # 자유롭게 사용 def update(self, index: int, val: int) -> None: # nums[index]의 값을 val로 바꾸시오 def sumRange(s..
1769. Minimum Number of Operations to Move All Balls to Each Box
·
Algorithm
Minimum Number of Operations to Move All Balls to Each Box - 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과 0으로 이루어진 문자열이 주어진다. 특정 index로 문자열의 모든 1을 이동시켰을 때의 비용 값을 반환하는 문제다. 한 칸 움직이는 비용은 1이다. Input: boxes = "001011" Output: [11,8,5,4,3,4] 0번 인덱스로 모든 1을 옮기려면 2,4,5번 인덱스의 1을 0번 인덱..
162. Find Peak Element
·
Algorithm
Find Peak Element - 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 정수 배열이 주어진다. 주어진 배열을 산의 높이라고 생각하고 Peek의 index를 반환하는 문제다. 산에는 여러 개의 Peek가 있을 수 있고 이런 경우는 조건에 해당하는 여러 개의 index 중 하나를 반환하면 된다. 예시 Input: nums = [1,2,3,1] Output: 2 Explanation: 3 is a peak element and your function sh..
1365. How Many Numbers Are Smaller Than the Current Number
·
Algorithm
How Many Numbers Are Smaller Than the Current Number - 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 ~ 100으로 이루어진 정수 배열이 주어진다. 해당하는 인덱스가 가리키는 정수보다 큰 정수가 배열에 몇 개 있는지 세어서 반환하는 문제다. # 예시 Input: nums = [8,1,2,2,3] Output: [4,0,1,1,3] Input: nums = [6,5,4,8] Output: [2,1,0,3] Input:..