标签:color return stc hash 剑指offer log lis mon ext
输入两个链表,找出它们的第一个公共结点。
import java.util.*; public class Solution { public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) { ListNode current1 = pHead1; ListNode current2 = pHead2; HashMap<ListNode,Integer> hashMap = new HashMap<ListNode,Integer>(); while(current1 != null){ hashMap.put(current1,null); current1 = current1.next; } while(current2 != null){ if(hashMap.containsKey(current2)){ return current2; } current2 = current2.next; } return null; } }
标签:color return stc hash 剑指offer log lis mon ext
原文地址:http://www.cnblogs.com/lfdingye/p/6142952.html