forked from Gerkins/arithmeticSum
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFirstCommonNodesInLists.java
More file actions
42 lines (38 loc) · 885 Bytes
/
Copy pathFirstCommonNodesInLists.java
File metadata and controls
42 lines (38 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* Created by lrkin on 2016/10/27.
*/
public class FirstCommonNodesInLists {
/**
* 方法一:
*
*
* 伪代码:
*
* 遍历,压栈
* public void transfer2Stack(root){
* Stack<Node> stackLong = new Stack<Node>;
* Stack<Node> stackShort = new Stack<Node>;
* while(rootLong.next){
* stackLong.push(rootLong);
* rootLong = rootLong.next;
* }
* while(rootShort.next){
* stackShort.push(root.short);
* rootShort = rootShort.next;
* }
* }
*
* //查找
* public Node find(node){
* Node nodeLong = stackLong.pop();
* Node nodeShort = stackShort.pop();
* if(nodeLong.data == nodeShort.data){
* theNode = nodeLong;
* //递归
* find(theNode);
* }else{
* return node;
* }
*}
*/
}