文件: root - text - article - 2019 - 11 - intersection-of-linked-lists.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | 英文 | 主页 | 类别: 计算机科学 | 443 次阅读, 21611 次搜索 | 136 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | 英文 | 主页 | 类别: 计算机科学 | 443 次阅读, 21611 次搜索 | 136 个单词
| 浏览 | 博客存档
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:
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, | 英文 | 主页 | 类别: 计算机科学 | 443 次阅读, 21611 次搜索 | 136 个单词 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
猜您喜欢...
- Plus One
- Algorithm Interview: No Adjacent Repeating Characters
- Daily Interview Problem: Decode String
- ImageMagick Vulnerabilities - CVE-2016–3714
- Algorithm Interview: String Compression
- Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
- Consecutive Ones
- Algorithm Interview: Convert Roman Numerals to Decimal
- Reverse a Directed Graph
- Daily Interview Problem: Maximum Profit From Stocks
©2006~2024 牛排过熟 - 0.00652 秒 - 3155.924 KB/s - 28 在线 内存: 493.79 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
牛排怎么做才好吃? | <meta name="机器人" content="索引, 跟踪">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
评论 (0)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。