• 문제 링크
Search in a Binary Search Tree - LeetCode
Can you solve this real interview question? Search in a Binary Search Tree - You are given the root of a binary search tree (BST) and an integer val. Find the node in the BST that the node's value equals val and return the subtree rooted with that node. If
leetcode.com
• 풀이 코드
public class Solution {
public TreeNode searchBST(TreeNode root, int val) {
if (root == null || root.val == val) return root;
return root.val > val ? searchBST(root.left, val) : searchBST(root.right, val);
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 704. Binary Search - Java (0) | 2026.09.29 |
|---|---|
| [LeetCode] 703. Kth Largest Element in a Stream - Java (0) | 2026.09.28 |
| [LeetCode] 697. Degree of an Array - Java (0) | 2026.09.26 |
| [LeetCode] 696. Count Binary Substrings - Java (0) | 2026.09.25 |
| [LeetCode] 693. Binary Number with Alternating Bits - Java (0) | 2026.09.24 |
댓글