728x90

LeetCode 24

[LeetCode] Easy - 100 Same Tree

▶100 - Same Tree ▶문제 Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. ▶예제 Input: p = [1,2,3], q = [1,2,3] Output: true Input: p = [1,2], q = [1,null,2] Output: false Input: p = [1,2,1], q = [1,1,2] Output: false ▶풀이 나는 각 트리의 값들을 직접 저장해..

LeetCode 2023.01.10

[LeetCode] Easy - 144 Binary Tree Preorder Traversal

▶144 - Binary Tree Preorder Traversal ▶문제 Given the root of a binary tree, return the preorder traversal of its nodes' values. ▶예제 Input: root = [1,null,2,3] Output: [1,2,3] Input: root = [] Output: [] Input: root = [1] Output: [1] ▶풀이 자료구조 때 배운 방식으로 preorder를 구성해서 풀었다.preorder는 left, right를 가기 전에 현재 node의 value값을 저장하거나 출력하는 방식이다. # Definition for a binary tree node. # class TreeNode: # def __in..

LeetCode 2023.01.09

[LeetCode] Hard - 149 Max Points on a Line

▶149 - Max Points on a Line ▶문제 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. ▶예제 Input: points = [[1,1],[2,2],[3,3]] Output: 3 Input: points = [[1,1],[3,2],[5,3],[4,1],[2,3],[1,4]] Output: 4 ▶풀이 단순히 모든 점들을 확인해보는 방식을 사용했다. 시간 복잡도가 O(n^2)가 나오는 방식이라서 시간초과가 날까 봐 걱정했지만 통과가 되었다. 점들의 기울기 ..

LeetCode 2023.01.08

[LeetCode] Medium - 1834 Single-Threaded CPU

▶1834 - Single-Threaded CPU ▶문제 You are given n​​​​​​ tasks labeled from 0 to n - 1 represented by a 2D integer array tasks, where tasks[i] = [enqueueTimei, processingTimei] means that the i​​​​​​th​​​​ task will be available to process at enqueueTimei and will take processingTimei to finish processing. You have a single-threaded CPU that can process at most one task at a time and will act in th..

LeetCode 2023.01.04
728x90