Skip to content

Commit 66f11b2

Browse files
committed
readme
1 parent 2943578 commit 66f11b2

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Success is like pregnancy, Everybody congratulates you but nobody knows how many
1111
## Linked List
1212
| # | Title | Solution | Time | Space | Difficulty |Tag| Note|
1313
|-----|-------| -------- | ---- | ------|------------|---|-----|
14-
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | [Python](./linkedlist/palindrome.py) | _O(n)_| _O(1)_ | Easy |CC189| Two Pointers|
1514
|21| [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists) | [Python](./linkedlist/MergeTwoSortedLists.py) | _O(n)_| _O(n)_ | Easy || Iteratively|
1615
| 89 | [Partition List](https://leetcode.com/problems/partition-list/) | [Python](./linkedlist/PartitionLinkedList.py) | _O(n)_ | _O(n)_ | Easy |CC189| |
1716
| 141 | [Partition List](https://leetcode.com/problems/linked-list-cycle/#/description) | [Python](./linkedlist/LinkedListCycle.py) | _O(n)_ | _O(1)_ | Easy |CC189| Two Pointers|
17+
|160|[Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists) | [Python](./linkedlist/IntersectionOfTwoLinkedLists.py) | _O(n)_| _O(1)_ | Easy || |
18+
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/) | [Python](./linkedlist/palindrome.py) | _O(n)_| _O(1)_ | Easy |CC189| Two Pointers|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class Solution:
2+
# @param two ListNodes
3+
# @return the intersected ListNode
4+
def getIntersectionNode(self, headA, headB):
5+
#Count the length for both listnode
6+
curA ,curB = headA ,headB
7+
len_a = self.lengthcount(curA)
8+
len_b = self.lengthcount(curB)
9+
10+
# Reset pointer, because they both pointers point to the end already.....
11+
curA ,curB = headA ,headB
12+
13+
#pad
14+
if len_a > len_b:
15+
for _ in xrange(len_a - len_b):
16+
curA = curA.next
17+
elif len_b > len_a:
18+
for _ in xrange(len_b - len_a):
19+
curB = curB.next
20+
21+
while curA != curB:
22+
curA = curA.next
23+
curB = curB.next
24+
25+
return curA
26+
27+
def lengthcount(self, head):
28+
count = 0
29+
while head:
30+
count += 1
31+
head = head.next
32+
return count

0 commit comments

Comments
 (0)