File: root - text - article - 2019 - 11 - intersection-of-linked-lists.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 446 Views, 21685 Search Bots | 136 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Category: Computing | 446 Views, 21685 Search Bots | 136 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Apple:
You are given two singly linked lists. The lists intersect at some node. Find, and return the node. Note: the lists are non-cyclical.
Example:
This should return 3 (you may assume that any nodes with the same value are the same node).
Here is a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | English | Home Page | Cateogry: Computing | 446 Views, 21685 Search Bots | 136 Words You are given two singly linked lists. The lists intersect at some node. Find, and return the node. Note: the lists are non-cyclical.
Example:
A = 1 -> 2 -> 3 -> 4
B = 6 -> 3 -> 4
This should return 3 (you may assume that any nodes with the same value are the same node).
Here is a starting point:
def intersection(a, b):
# fill this in.
class Node(object):
def __init__(self, val):
self.val = val
self.next = None
def prettyPrint(self):
c = self
while c:
print c.val,
c = c.next
a = Node(1)
a.next = Node(2)
a.next.next = Node(3)
a.next.next.next = Node(4)
b = Node(6)
b.next = a.next.next
c = intersection(a, b)
c.prettyPrint()
# 3 4
Related Articles
- Daily Interview Problem: Jump to the End
- Algorithm Interview Question: Max and Min with Limited Comparisons
- Design Tic-Tac-Toe
- Daily Interview Question: Edit Distance
- Daily Interview Problem: Reverse Words in a String
- Daily Interview Puzzle: Intersection of Linked Lists
- Non-decreasing Array with Single Modification
- Invert a Binary Tree
- Daily Interview Problem: Full Binary Tree
- Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
©2006~2024 SteakOverCooked - 0.00809 Seconds(s) - 2389.392 KB/s - 42 Online Memory: 491.53 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !