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

Related Articles

  1. Number of Ways to Climb Stairs
  2. Delphi Dynamic Array
  3. Daily Interview Problem: Buddy Strings
  4. Daily Interview Problem: Full Binary Tree
  5. Daily Interview Problem: Min Stack
  6. Floor and Ceiling of a Binary Search Tree
  7. Daily Interview Problem: Reconstrunct Binary Tree from Preorder and Inorder Traversals
  8. Daily Interview Problem: Spiral Traversal of Grid
  9. Daily Interview Problem: Reverse Integer
  10. [Daily Problem] Validate Balanced Parentheses

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="index, follow">