Tuesday, June 13, 2017

Flatten a multi-level linked list Depth


http://www.geeksforgeeks.org/flatten-a-multi-level-linked-list-set-2-depth-wise/

Fibonacci Recursion and Iterative


First 9 Fibonacci number 
1 1 2 3 5 8 13 21 34

[Leetcode]Largest Number


https://leetcode.com/problems/largest-number/#/description

Given a list of non negative integers, arrange them such that they form the largest number.
For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
1. A naive approach would be put 9 in front of 5, 4, 3. but that would be way too complex for the case when we have 5656 and 56. The right approach is to compare numbers like that. Let’s say we have [3, 34]. We combine them to 343 and 334. 343 is larger than 334 so our list will be sorted to [34, 3]
2. define your own comparator, 1 if a > b, -1 if a < b 3. Syntax for using customized comparator in sorted() sorted(list, cmp = self.methodName)

[Leetcode]Swap Nodes in Pairs


https://leetcode.com/problems/largest-number/

  1. in Line 17 , you need to have a clear mind what is the new value for curr. curr = one will do the work but might be confusing. curr = curr.next.next is sound and safe