摘要:
Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15,18],return[1,6],[8,10],[15,18].思路:首先以start排序,... 阅读全文
摘要:
Mergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.思路:开始做过两两合并的链表,此时做k路合并,即将k个链表进行合并,可以先将这k个链表进行两两合并,知道合并... 阅读全文
摘要:
Implementint sqrt(int x).Compute and return the square root ofx.这里给出两种实现方法:一是二分搜索,二是牛顿迭代法。1. 二分搜索对于一个非负数n,它的平方根不会小于大于(n/2+1)。在[0, n/2+1]这个范围内可以进行二分搜索,... 阅读全文
摘要:
Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should ru... 阅读全文
摘要:
Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.C++实现代码:#inclu... 阅读全文
摘要:
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.提交成功的代码:C++实现:#... 阅读全文
摘要:
Dynamic ProgrammingGiven a stringSand a stringT, count the number of distinct subsequences ofTinS.A subsequence of a string is a new string which is f... 阅读全文