File: root - text - article - 2019 - 11 - merge-k-sorted-linked-list.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 474 Views, 21867 Search Bots | 98 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 474 Views, 21867 Search Bots | 98 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
You are given an array of k sorted singly linked lists. Merge the linked lists into a single sorted linked list and return it.
Here's your starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 474 Views, 21867 Search Bots | 98 Words You are given an array of k sorted singly linked lists. Merge the linked lists into a single sorted linked list and return it.
Here's your starting point:
class Node(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
def __str__(self):
c = self
answer = ""
while c:
answer += str(c.val) if c.val else ""
c = c.next
return answer
def merge(lists):
# Fill this in.
a = Node(1, Node(3, Node(5)))
b = Node(2, Node(4, Node(6)))
print merge([a, b])
# 123456
Related Articles
- Algorithm Interview: Convert Roman Numerals to Decimal
- Staying on a Chess Board
- Plus One
- Design Tic-Tac-Toe
- Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
- Windows Scripting
- Daily Interview Problem: Given two arrays, write a function to compute their intersection.
- Daily Interview Problem: Product of Array Except Self
- Daily Interview Problem: Room scheduling
- Daily Interview Question: Longest Sequence with Two Unique Numbers
©2006~2024 SteakOverCooked - 0.00862 Seconds(s) - 2261.758 KB/s - 23 Online Memory: 492.68 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="index, 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 !