We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 2bac133 + b5e3b80 commit 6835cb7Copy full SHA for 6835cb7
problems/0236.二叉树的最近公共祖先.md
@@ -454,7 +454,11 @@ impl Solution {
454
p: Option<Rc<RefCell<TreeNode>>>,
455
q: Option<Rc<RefCell<TreeNode>>>,
456
) -> Option<Rc<RefCell<TreeNode>>> {
457
- if root == p || root == q || root.is_none() {
+ if root.is_none() {
458
+ return root;
459
+ }
460
+ if Rc::ptr_eq(root.as_ref().unwrap(), p.as_ref().unwrap())
461
+ || Rc::ptr_eq(root.as_ref().unwrap(), q.as_ref().unwrap()) {
462
return root;
463
}
464
let left = Self::lowest_common_ancestor(
0 commit comments