Zero to Hero
article thumbnail
654. Maximum Binary Tree
Algorithm 2021. 8. 10. 11:01

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..

article thumbnail
1551. Minimum Operations to Make Array Equal
Algorithm 2021. 8. 8. 10:07

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]이다. 결국..

article thumbnail
1329. Sort the Matrix Diagonally
Algorithm 2021. 8. 7. 08:43

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..

article thumbnail
N*N, N**2, pow(N, 2), math.pow(N,2)
Programming 2021. 8. 6. 10:08

이전에 재밌는 문제를 풀었다. 관련 내용은 아래 포스팅 참고. 1828. Queries on Number of Points Inside a Circle 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. l.. doljae.tistory.com 사실 이 문제는 문제 자체가 주는 의미도 있지만, Python을 알고리즘 문제 해결에 사용하는 사람들은 한 번쯤은 생각해볼 부분이 있다. 바로 거듭제곱 연산이다. Py..

article thumbnail
1828. Queries on Number of Points Inside a Circle
Algorithm 2021. 8. 6. 09:32

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..

보호되어 있는 글입니다. 내용을 보시려면 비밀번호를 입력해주세요.