Leetcode Problem Pascal’s Triangle II rowIndex가 주어졌을 때, 파스칼 삼각형에서 해당 층의 배열을 구하는 문제입니다. class Solution: def getRow(self, rowIndex: int) -> List[int]: pascal = [[1]] for i in...
Pascal's Triangle
Leetcode Problem Pascal’s Triangle numRows가 주어졌을 때, 해당 층 수까지의 파스칼 삼각형을 구하는 문제입니다. class Solution: def generate(self, numRows: int) -> List[List[int]]: pascal = [[1]] num = ...
Path Sum
Leetcode Problem Path Sum binary tree가 주어졌을 때, leaf node까지의 합과 targetSum이 일치하는 경우가 있는지를 판별하는 문제입니다. class Solution: def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool: ...
Minimum Depth of Binary Tree
Leetcode Problem Minimum Depth of Binary Tree 주어진 binary tree에서, root부터 leaf node까지의 최소 높이를 구하는 문제입니다. leaf node는 자식 node가 없습니다. class Solution: def minDepth(self, root: Optional[TreeNode]) -...
Balanced Binary Tree
Leetcode Problem Balanced Binary Tree 이진 tree가 주어졌을 때, height-balanced한지를 판별하는 문제입니다. class Solution: def getHeight(self, root: Optional[TreeNode]): if not root: return 0...
Convert Sorted Array to Binary Search Tree
Leetcode Problem Convert Sorted Array to Binary Search Tree 오름차순으로 정렬된 배열이 주어졌을 때, 이를 height balanced binary search tree로 바꾸는 문제입니다. class Solution: def sortedArrayToBST(self, nums: List[int]...
Maximum Depth of Binary Tree
Leetcode Problem Maximum Depth of Binary Tree binary tree의 최대 깊이를 구하는 문제입니다. class Solution: def maxDepth(self, root: Optional[TreeNode]) -> int: return max(self.maxDepth(root.left...
Symmetric Tree
Leetcode Problem Symmetric Tree 두 binary tree가 대칭인지를 비교하는 문제입니다. class Solution: def isSymmetric(self, root: Optional[TreeNode]) -> bool: def symmetric(left: Optional[TreeNode], ri...
Same Tree
Leetcode Problem Same Tree 두 binary tree가 같은지를 비교하는 문제입니다. class Solution: def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool: def preorder(p: Optional[Tree...
Convert Sorted Array to Binary Search Tree
Leetcode Problem Convert Sorted Array to Binary Search Tree 주어진 tree에 대해서 inorder로 순회한 결과를 배열에 저장하는 문제입니다. # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, l...