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 | 399 Views, 20852 Search Bots | 98 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 399 Views, 20852 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 | 399 Views, 20852 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
- Progess made
- Generate All IP Addresses
- Algorithm Interview Question: Find the Single Element in an Array of Duplicates
- Algorithm Interview: Make the Largest Number
- Design Tic-Tac-Toe
- Spectrum Master
- Absolute Path
- Find the non-duplicate number
- Algorithm Interview: String Compression
- Daily Interview Problem: Merge Overlapping Intervals
©2006~2024 SteakOverCooked - 0.01069 Seconds(s) - 1781.774 KB/s - 7 Online Memory: 492.41 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 !