We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a55f623 commit 5cef50bCopy full SHA for 5cef50b
C++/inorder-successor-in-bst.cpp
@@ -14,7 +14,7 @@ class Solution {
14
public:
15
TreeNode* inorderSuccessor(TreeNode* root, TreeNode* p) {
16
// If it has right subtree.
17
- if (p->right) {
+ if (p && p->right) {
18
p = p->right;
19
while (p->left) {
20
p = p->left;
0 commit comments