Java bit path  Time : O(logn)
Think about it with complete binary tree and the whole idea is to binary serialize the target number. It\'s actually tha order we doing the dfs.\nLet\'s say our
Think about it with complete binary tree and the whole idea is to binary serialize the target number. It\'s actually tha order we doing the dfs.\nLet\'s say our target : 9 we shall take it as 10 : 1010  ignoring the first digit 1 the path ( 010 )  means left -> right -> left  \nSo \'0\' means going to the left and \'1\' means going to the right.\nHere is the picture, very straightforward.\n\n![image](https://assets.leetcode.com/users/jiaweizhang1994/image_1574045418.png)\n\n\n\n\n\n\n\n\n\n\tTreeNode root;\n\n    public FindElements(TreeNode root) {\n        this.root = root;\n    }\n    \n    public boolean find(int target) {\n        return dfs(root, binSerialize(target + 1), 1);\n    }\n\t\n\tpublic boolean dfs(TreeNode root, String str, int pos){\n        if(root == null)    return false;\n        if(pos == str.length()) return true;\n        return str.charAt(pos) == \'0\'? dfs(root.left, str, pos+1) : dfs(root.right, str, pos+1);\n    }\n    \n    public String binSerialize(int num){\n        StringBuilder sb = new StringBuilder();\n        while(num > 0){\n            sb.insert(0, num & 1);\n            num /= 2;\n        }\n        return sb.toString();\n    }\n    \n\n
[]