Maximum 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 중복된 값이 없는 정수로 구성된 list가 주어진다. 이 list를 이용해서 아래 조건에 부합하는 tree를 만들어 root를 반환하는 문제다. 1. Create a root node whose value is the maximum value in nums. 2. Recursively build the left subtree on the subarray prefix to the..
Minimum Operations to Make Array Equal - 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이 주어진다. 1부터 시작하는 홀수 N개의 배열 arr에 대해서 아래 연산 법을 사용할 수 있다. 연산 법 len를 arr의 길이, 0 int: return n * n // 4 이 문제는 수의 성질을 이용하면 O(1)로 해결할 수 있는 문제다. 홀수인 경우 n = 7이라면 arr = [1, 3, 5, 7, 9, 11, 13]이다. 결국..
Sort the Matrix Diagonally - 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차원 배열이 주어진다. 배열을 우측 하단 대각성 방향으로 오름차순 정렬한 뒤 반환하는 문제다. 1. 구현 from typing import * class Solution: def diagonalSort(self, mat: List[List[int]]) -> List[List[int]]: if not mat: return None height, width = len..
Queries on Number of Points Inside a Circle - 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개의 점이 입력으로 주어진다. 해당 원 안에 포함되거나 걸치는 점의 개수를 각각의 원에 대해서 반환하는 문제다. from typing import * class Solution: def countPoints(self, points: List[List[int]], queries: List[L..
Check if the Sentence Is Pangram - 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 소문자로 이루어진 영문 문자열이 주어진다. 주어진 문자열이 알파벳 26개가 모두 1번 이상 출현한다면 True를, 그렇지 않다면 False를 반환하는 문제다. 1. Set, discard() class Solution: def checkIfPangram(self, sentence: str) -> bool: alphabet_set = set([chr(i) ..