본문 바로가기
Problem Solving/LeetCode

[LeetCode] 700. Search in a Binary Search Tree - Java

by graycode 2026. 9. 27.

• 문제 링크

 

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);
    }

}

댓글