K21
Search in a Binary Search Tree
Problem Statement & Objective
Given the root of a binary search tree (BST) and an integer val, find the node in the BST whose value equals val and return the subtree rooted with that node.
Function Signature (Python)
search_in_a_binary_search(root: list, val: int) -> listInput & Output Contract
Output Rule:Alt ağacın düğüm değerleri listesi. Yoksa [].
System Constraints
0 <= agac.length <= 5000
-10^4 <= agac[i], val <= 10^4Example Execution Walkthrough
agac = [4, 2, 7, 1, 3], val = 2 -> 2'nin alt ağacı [2, 1, 3]Example Test Scenarios (3)
Example 1
Input:
[[4,2,7,1,3],2]Expected Output:
[2,1,3]Example 2: Bulunamadı
Input:
[[4,2,7,1,3],5]Expected Output:
[]Example 3: Sağ Yaprak
Input:
[[4,2,7],7]Expected Output:
[7]