摘要:
Follow up for "Remove Duplicates": What if duplicates are allowed at most twice?For example, Given sorted array A = [1,1,1,2,2,3],Your function should return length = 5, and A is now [1,1,2,2,3].思考:双指针,A[i]与A[cur]前两个值比较。class Solution {public: int removeDuplicates(int A[], int n) { // IMPO 阅读全文
摘要:
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./** * Def... 阅读全文
摘要:
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?思考:DP,斐波拉契。class Solution {public: int climbStairs(int n) { // IMPORTANT: Please reset any member data you declared, as ... 阅读全文
摘要:
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].思考:先排序。比较相邻两个interval,left为前一个start,若后一个start小于等于前一个,说明这两个interval需要合并,right为两个end较大者。若后一个start大于前一个end,说明这两个interval不需要合并,输出前一个。/** * Definition for an interva 阅读全文