본문 바로가기

전체 글196

leet code - 2145. Count the Hidden Sequences (medium, math) You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidden, then we have that differences[i] = hidden[i + 1] - hidden[i].You are further given two integers lower and upper that describe the inclusive range of values [lower, upper] that t.. 2025. 4. 22.
leet code - 149. Max Points on a Line (hard, math) Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line. Example 1:Input: points = [[1,1],[2,2],[3,3]]Output: 3Example 2:Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]]Output: 4 Constraints:1 points[i].length == 2-104 All the points are unique. points.length = 300 으로 모든 점 쌍에 대해 기울기를 계산.. 2025. 4. 20.
leet code - 124. Binary Tree Maximum Path Sum (hard, matrix) leet code - 124. Binary Tree Maximum Path Sum (hard, dfs post order) A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root.The path sum of a path is the sum of the node's values in the path.Given the root of a binar.. 2025. 4. 20.
leet code - 59. Spiral Matrix II (medium, matrix) leet code - 59. Spiral Matrix II (medium, matrix)Given a positive integer n, generate an n x n matrix filled with elements from 1 to n2 in spiral order. Example 1: Input: n = 3Output: [[1,2,3],[8,9,4],[7,6,5]]Example 2:Input: n = 1Output: [[1]] Constraints:1 n이라는 숫자가 주어지면 n*n 크기의 매트릭스를 생성해나선 순회를 하면서 해당 순서의 숫자로 update def generateMatrix(self, n: int) -> List[List[int]]: x, y, .. 2025. 4. 17.