Google | Check if a node exists in a complete tree
Anonymous User
12873

Given a complete (virtual) binary tree, return true/false if the given target node exists in the tree or not. Here, the virtual means the tree nodes are numbered assuming the tree is a complete binary tree.

Example:

                1
		    /        \ 
		 2              3
       /   \           /  \ 
     4   (5)nil      6  (7)nil
   
doesNodeExist(root, 4); // true
doesNodeExist(root, 7); // false, given the node on #7 is a nil node

Follow-up:
https://leetcode.com/problems/count-complete-tree-nodes

Comments (16)