摘要:
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, 阅读全文
摘要:
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 阅读全文
摘要:
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. 思路: 由于链表 阅读全文
摘要:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 思路:利用快慢指针找到中间节点,作为根节点,然后左子树即为左边链表部分,右子树即 阅读全文
摘要:
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 阅读全文
摘要:
Given two strings representing two complex numbers. You need to return a string representing their multiplication. Note i2 = -1 according to the defin 阅读全文
摘要:
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 思路: 由于是有序数组,那么根节点肯定是中间的那个数字,然后递归处理左子树和右子树即可。 阅读全文
摘要:
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 阅读全文
摘要:
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng 阅读全文
摘要:
Implement pow(x, n). 开始的时候思路很朴素,隐约觉得不太对劲。。果然,超时了。 然后,再仔细琢磨,发现可以缩短时间,缩短到 O(lgn)的复杂度。 比如8个2相乘的话,可以表示为4的平方,4又可以表示为2的平方,只需三次即可算出。 参考: https://discuss.leet 阅读全文