700. Search in a Binary Search Tree

양성준·2025년 5월 27일

코딩테스트

목록 보기
69/102

문제

https://leetcode.com/problems/search-in-a-binary-search-tree/description/

풀이

class Solution {
    public TreeNode searchBST(TreeNode root, int val) {
        if(root == null) {
            return null;
        }

        if(root.val == val) {
            return root;
        } else if(root.val > val) {
            return searchBST(root.left, val);
        } else  {
            return searchBST(root.right, val);
        }
    }
}
profile
백엔드 개발자를 꿈꿉니다.

0개의 댓글