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

Related Articles

  1. Daily Interview Problem: Tree Serialization
  2. Algorithm Interview: Convert Roman Numerals to Decimal
  3. Two Tricks of Delphi
  4. [Daily Problem] Longest Palindromic Substring
  5. Daily Interview Problem: Word Ordering in a Different Alphabetical Order
  6. Algorithm Interview Question: H-Index
  7. Fibonacci coding
  8. ImageMagick Vulnerabilities -  CVE-2016–3714
  9. Algorithm Interview: Permutations of numbers
  10. Daily Interview Problem: Group Words that are Anagrams

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