class FindElements { HashSet<Integer> hs; public void Recover(TreeNode root,int val){ hs.add(val); if(root==null) return ; if(root.left!=null){ Recover(root.left,val*2+1);} if(root.right!=null){ Recover(root.right,val*2+2); } } public FindElements(TreeNode root) { hs=new HashSet<>(); Recover(root,0); } public boolean find(int target) { if(hs.contains(target)) return true; return false; } }
@bootcoder-himanshu