# Daily Archives: January 19, 2015

## [leetcode] Merge k Sorted Lists

Merge k Sorted Lists Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Tag: divide and conquer, linked list, heap update 9/22/2015 Merge sort the k lists. O(knlogk) in time, O(1) //merge these /** * Definition for singly-linked list. * struct ListNode […]

## [leetcode] Swap Nodes in Pairs

Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. […]

## [leetcode] Best Time to Buy and Sell Stock II

Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy one and sell […]

## [leetcode] Best Time to Buy and Sell Stock1

Description: Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design […]