To the Top
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 | 189 Views, 16713 Search Bots | 98 Words

Subscribe to Feed Burner | 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:


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
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 189 Views, 16713 Search Bots | 98 Words Subscribe to Feed Burner

Related Articles

  1. Staying on a Chess Board
  2. Batch Programming in XP
  3. Two Tricks of Delphi
  4. Making a Height Balanced Binary Search Tree
  5. Daily Interview Problem: Get all Values at a Certain Height in a Binary Tree
  6. Find Missing Numbers in an Array
  7. Algorithm Interview Question: Nth Fibonacci Number
  8. Daily Interview Problem: Merge K Sorted Linked Lists
  9. Patterns for breaking down questions you haven
  10. Fix Brackets

Comments (0)

Your Email (Domain Part Not Exposed):

Your Comments:

Privately By Mail Colors More Smileys S x y @

Verification (Click Image 2 Refresh):

    Be the first one to comment this page !


Page Edited: October 30 2020 14:21:09 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />