求树中两个节点的最低公共祖先(三)

2015-07-24 05:57:30 · 作者: · 浏览: 25
or2( A, B, D); System.out.println("The lowest common ancestor of 5 and 6 is " +res1.value); System.out.println("The lowest common ancestor of 4 and 5 is " +res2.value); System.out.println("The lowest common ancestor of 2 and 4 is " +res3.value); } 结果:

The lowest common ancestor of 5 and6 is 1

The lowest common ancestor of 4 and5 is 2

The lowest common ancestor of 2 and 4 is 1