본문 바로가기

전체 글

[Leetcode/파이썬] 134. Gas Station Gas StationThere are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations.Given two integer arrays gas and cost, return the starting gas station's index if you.. 더보기
[Leetcode/파이썬] 35. Search Insert Position Search Insert PositionGiven a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity. Example 1:Input: nums = [1,3,5,6], target = 5Output: 2Example 2:Input: nums = [1,3,5,6], target = 2Output: 1Example 3:Input: nums = [1,3,5,.. 더보기
[Leetcode/파이썬] 221. Maximal Square Maximal SquareGiven an m x n binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area. Example 1:Input: matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]Output: 4Example 2:Input: matrix = [["0","1"],["1","0"]]Output: 1Example 3:Input: matrix = [["0"]]Output: 0 Constraints:m == matrix.lengthn == matrix[.. 더보기
[Leetcode/파이썬] 289. Game of Life Game of LifeAccording to Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."The board is made up of an m x n grid of cells, where each cell has an initial state: live (represented by a 1) or dead (represented by a 0). Each cell interacts with its eight neighbors (horizontal, vertical, diagona.. 더보기
[Leetcode/파이썬] 100.Same Tree Same TreeGiven 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. Example 1:Input: p = [1,2,3], q = [1,2,3]Output: trueExample 2:Input: p = [1,2], q = [1,null,2]Output: falseExample 3:Input: p = [1,2,1], q = [1,1,2]Output: false Constraints:The.. 더보기
[Leetcode/파이썬] 114. Flatten Binary Tree to Linked List Flatten Binary Tree to Linked ListGiven the root of a binary tree, flatten the tree into a "linked list":The "linked list" should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null.The "linked list" should be in the same order as a pre-order traversal of the binary tree. Example 1:Input: root = [1,2,5,3,4,null,6.. 더보기
[Leetcode/파이썬] 13. Roman to Integer Roman to IntegerRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2 is written as II in Roman numeral, just two ones added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which i.. 더보기
[Leetcode/파이썬] 236. Lowest Common Ancestor of a Binary Tree Product of Array Except SelfGiven an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.You must write an algorithm that runs in O(n) time and without using the division operation. Example 1:Input: nums = [1,2,3,4]Output: [24,12,8,6]E.. 더보기