The general reason is that it’s not initialized, it’s running as a random number;
Or it returns a wild pointer, which is common in test cases with empty sets and requires a pointer to be returned. Most of the time, it will be like this without attention:
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
TreeNode *result;
if(preorder.size() == 0 && inorder.size() == 0)
return result;
else
return sub_bT(0, preorder.size()-1, 0, inorder.size()-1, preorder, inorder);
}
At this time, we often think that a null pointer is returned, but in fact, it is not initialized. What is returned is a wild pointer, which does not know where to point to. However, when we Run Code, no error will be reported and the result is [], so we think that a null pointer is returned.
TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
TreeNode *result(NULL);
if(preorder.size() == 0 && inorder.size() == 0)
return result;
else
return sub_bT(0, preorder.size()-1, 0, inorder.size()-1, preorder, inorder);
}
Read More:
- Error: php56w-common conflicts with php-common-5.3.3-48.el6_ 8.x86_ 64
- Leetcode 832. Flip image
- The sum of the two numbers of leetcode
- The docker runtime container reported an error: error response from daemon: OCI runtime create failed
- LeetCode 23. Merge k Sorted Lists(java)
- Leetcode: 7. Reverse Integer(JAVA)
- LeetCode 332. Reconstruct Itinerary
- Leetcode-234: palindrome linked list
- Leetcode solution 189 Rotate Array Java version
- Leetcode 34 finds the first and last position of an element in the sorted array (medium)
- R-common errors and their possible causes — Notes
- Cause of runtime error on OJ
- Common errors and modification methods of findbug
- 1143 Lowest Common Ancestor
- panic: runtime error: index out of range
- Summary of common runtimeException exceptions
- Yarn: runtime.ContainerExecutionException : launch container failed
- Linux common problems and Solutions
- Common problems and basic concept knowledge of OpenGL
- Common errors and solutions in MapReduce stage