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 | 260 Views, 20303 Search Bots | 98 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 260 Views, 20303 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 | 260 Views, 20303 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
- Palindrome Integers
- Sort a Partially Sorted List
- Daily Interview Problem: Find the k-th Largest Element in a List
- Daily Interview Problem: Arithmetic Binary Tree
- Algorithm Interview: Level Order Traversal of Binary Tree
- Number of Ways to Climb Stairs
- Kaprekar
- [Daily Problem] Witness of The Tall People
- Non-decreasing Array with Single Modification
- [Daily Problem] Angles of a Clock
©2006~2024 SteakOverCooked - 0.01273 Seconds(s) - 1588.755 KB/s - 24 Online Memory: 493.61 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 !