Fork me on GitHub
摘要: Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3, 阅读全文
posted @ 2017-03-29 17:18 hellowOOOrld 阅读(211) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmet 阅读全文
posted @ 2017-03-28 23:13 hellowOOOrld 阅读(214) 评论(0) 推荐(0) 编辑
摘要: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 思路: 由于链表 阅读全文
posted @ 2017-03-27 22:55 hellowOOOrld 阅读(206) 评论(0) 推荐(0) 编辑
摘要: Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 思路:利用快慢指针找到中间节点,作为根节点,然后左子树即为左边链表部分,右子树即 阅读全文
posted @ 2017-03-26 23:27 hellowOOOrld 阅读(850) 评论(0) 推荐(0) 编辑
摘要: We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write 阅读全文
posted @ 2017-03-26 11:16 hellowOOOrld 阅读(322) 评论(0) 推荐(0) 编辑
摘要: Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = -1 according to the defin 阅读全文
posted @ 2017-03-26 11:13 hellowOOOrld 阅读(474) 评论(0) 推荐(0) 编辑
摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路: 由于是有序数组,那么根节点肯定是中间的那个数字,然后递归处理左子树和右子树即可。 阅读全文
posted @ 2017-03-23 16:53 hellowOOOrld 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from some starting node to any node in th 阅读全文
posted @ 2017-03-23 15:18 hellowOOOrld 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng 阅读全文
posted @ 2017-03-16 16:53 hellowOOOrld 阅读(148) 评论(0) 推荐(0) 编辑
摘要: Implement pow(x, n). 开始的时候思路很朴素,隐约觉得不太对劲。。果然,超时了。 然后,再仔细琢磨,发现可以缩短时间,缩短到 O(lgn)的复杂度。 比如8个2相乘的话,可以表示为4的平方,4又可以表示为2的平方,只需三次即可算出。 参考: https://discuss.leet 阅读全文
posted @ 2017-03-15 17:06 hellowOOOrld 阅读(164) 评论(0) 推荐(0) 编辑