전체 글66 [LeetCode] Validate Binary Search Tree 문제Given the root of a binary tree, determine if it is a valid binary search tree (BST).A valid BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater than the node's key.Both the left and right subtrees must also be binary search trees.예시Input: root = [2,1,3]Output: trueInput: r.. 2025. 3. 1. [LeetCode] Maximum Depth of Binary Tree 문제Given the root of a binary tree, return its maximum depth.A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. 예시Input: root = [3,9,20,null,null,15,7]Output: 3Input: root = [1,null,2]Output: 2 풀기트리의 최대 깊이를 찾아내는 문제로 나는 DFS를 통해 풀어야겠다고 생각했다.BFS를 통해서 풀 수도 있다고 함. 백준에서 배열에다 값을 넣어 풀어보기만 했지 LeetCode의 주어진 클래스 TreeNode를 어떻게 활용할지 몰.. 2025. 2. 27. [LeetCode] Min Stack 문제Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.Implement the MinStack class:MinStack() initializes the stack object.void push(int val) pushes the element val onto the stack.void pop() removes the element on the top of the stack.int top() gets the top element of the stack.int getMin() retrieves the minimum element in the stack.You must implement.. 2025. 2. 26. [LeetCode] House Robber 문제You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night.Given an integer array nums representing the amount of mone.. 2025. 2. 25. 이전 1 2 3 4 ··· 17 다음