上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 19 下一页
摘要: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263/** * Definition for singly-linked list. * struct ListNode { * int val; * L... 阅读全文
posted @ 2017-01-13 14:04 copperface 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析算法1:类似于归并排序,将Merge k 个的问题,拆分成Merge 2 个的子任务,然后递归回溯。算法复杂度 O(nlogn)算法2:使用最小堆。维护一个最大 大小 k 的最小堆,每次从堆顶pop出... 阅读全文
posted @ 2017-01-13 14:03 copperface 阅读(242) 评论(0) 推荐(0) 编辑
摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "... 阅读全文
posted @ 2017-01-04 22:37 copperface 阅读(158) 评论(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.分析:就是使用两个指针,让较小的归并到新的list上:代码:方法一:1234567891011121314151617... 阅读全文
posted @ 2017-01-03 22:43 copperface 阅读(188) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linke... 阅读全文
posted @ 2017-01-03 22:42 copperface 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but ... 阅读全文
posted @ 2017-01-03 22:42 copperface 阅读(131) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution set m... 阅读全文
posted @ 2016-12-09 23:22 copperface 阅读(205) 评论(0) 推荐(0) 编辑
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input: Digit string "23"... 阅读全文
posted @ 2016-12-07 22:22 copperface 阅读(234) 评论(0) 推荐(0) 编辑
摘要: Write a function to find the longest common prefix string amongst an array of strings.1234567891011121314class Solution {public: string longestCommonPrefix(vector& strs) { if(strs.empty()) r... 阅读全文
posted @ 2016-12-07 16:22 copperface 阅读(142) 评论(0) 推荐(0) 编辑
摘要: Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly... 阅读全文
posted @ 2016-12-07 16:21 copperface 阅读(208) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 19 下一页