摘要: 根据提示,本题等价于pre order traverse遍历,并且依次把所有的节点都存成right child,并把left child定义成空集。用递归的思想,那么如果分别把左右子树flatten成list,我们有: 1 / \ 2 5 \ \ 3 6 <- rightTail \ 4 <- le 阅读全文
posted @ 2016-12-19 06:27 lettuan 阅读(117) 评论(0) 推荐(0) 编辑
摘要: There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every 阅读全文
posted @ 2016-12-19 06:10 lettuan 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Additive number is a string whose digits can form additive sequence. A valid additive sequence should contain at least three numbers. Except for the f 阅读全文
posted @ 2016-12-18 10:29 lettuan 阅读(554) 评论(0) 推荐(0) 编辑
摘要: Given an unsorted array of integers, find the length of longest increasing subsequence. For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest inc 阅读全文
posted @ 2016-12-17 06:55 lettuan 阅读(165) 评论(0) 推荐(0) 编辑
摘要: Given a string s and a string t, check if s is subsequence of t. You may assume that there is only lower case English letters in both s and t. t is po 阅读全文
posted @ 2016-12-17 06:17 lettuan 阅读(184) 评论(0) 推荐(0) 编辑
摘要: Given a positive integer n and you can do operations as follow: What is the minimum number of replacements needed for n to become 1? Example 1: Exampl 阅读全文
posted @ 2016-12-17 05:24 lettuan 阅读(238) 评论(0) 推荐(0) 编辑
摘要: Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. 阅读全文
posted @ 2016-12-16 12:04 lettuan 阅读(273) 评论(0) 推荐(0) 编辑
摘要: Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. For example, giv 阅读全文
posted @ 2016-12-16 10:21 lettuan 阅读(86) 评论(0) 推荐(0) 编辑
摘要: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Find the minimum element. 阅读全文
posted @ 2016-12-16 06:42 lettuan 阅读(96) 评论(0) 推荐(0) 编辑
摘要: 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 n 阅读全文
posted @ 2016-12-16 06:04 lettuan 阅读(121) 评论(0) 推荐(0) 编辑