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 | 190 Views, 16957 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 | 190 Views, 16957 Search Bots | 98 Words Subscribe to Feed Burner

Related Articles

  1. CPU Utilization
  2. Algorithm Interview: Make the Largest Number
  3. Making a Height Balanced Binary Search Tree
  4. Daily Interview Problem: Arithmetic Binary Tree
  5. Delphi Dynamic Array
  6. Daily Interview Problem: Circle of Chained Words
  7. Floor and Ceiling of a Binary Search Tree
  8. Progess made
  9. Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
  10. Daily Interview Puzzle: Minimum Size Subarray Sum

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />