fwnx- find the common ancestor in a tree
来源:互联网 发布:php substr函数 编辑:程序博客网 时间:2024/05/17 06:09
1 if the nodes are in the left tree then find the common ancestor in the left tree
2 if the nodes are in the right tree then find the common ancestor in the right tree
3 if the nodes are in different tree of the node root; then return the root;
-- so easy but absolutely correct statement;
boolean covers(Node root,Node test){// is test is the child of root ?if(root == null) return false;if(root == test) return true;return covers(root.left_child,test) || covers(root.right_child,test);}Node findCommoAn(Node root,Node nd1,Node nd2){if(covers(root.right_child,nd1) && covers(root.right_child,nd2)){// if nd1 and nd2 both at the right tree; returnfindCommoAn(root.right_child,nd1,nd2);}// if nd1 and nd2 both at the left tree if(covers(root.left_child,nd1) && covers(root.left_child,nd2)){return findCommoAn(root.left_child,nd1,nd2);}return root;}
0 0
- fwnx- find the common ancestor in a tree
- Find the nearest common ancestor of any two nodes in a binary search tree
- Find the common ancestor of two nodes in a binary tree
- Least Common Ancestor in a Binary Tree
- Lowest Common Ancestor in a Binary Tree
- FWNX - find the same father - TREE
- Lowest Common Ancestor of The Two Nodes in a Binary Tree
- Find the First Common Ancestor
- Lowest Common Ancestor in a Binary Search Tree.
- fwnx - find the middle node in the linked list ~~~
- Lowest common ancestor in binary search tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Lowest Common Ancestor of a Binary Tree
- Ruby命令行参数介绍
- [LeetCode] Unique Binary Search Trees
- DP34 流水线调度问题 Assembly Line Scheduling @geeksforgeeks
- fwnx - 4.7 tree contains ; recursive
- Ch1-5: Write a method to replace all spaces in a string with ‘%20’.
- fwnx- find the common ancestor in a tree
- [LeetCode] Spiral Matrix
- cocos2d-x游戏开发系列教程-中国象棋06-游戏规则
- [LeetCode] Minimum Path Sum
- IRP IO_STACK_LOCATION 《寒江独钓》内核学习笔记(1)
- DP35 最长等差数列 Longest Arithmetic Progression @geeksforgeeks
- 从网络获取图片方法
- Ch1.6: IN-place-ly rotate a pic(NxN matrix) by 90 digree in Verilog(CPP)
- DP36 如何切出最大长度乘积 Maximum Product Cutting @geeksforgeeks