01 2017 档案
摘要:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible ord...
        阅读全文
            
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wi...
        阅读全文
            
摘要:KMP背景分析普通算法(遍历),会遗忘所有之前比较过的信息,导致每一次移位,都要重新重头比较每一个字符。这将会导致 O(mn)的时间复杂度(m: 关键字符长度,n: 文本string的长度)而KMP算法,则能够保证不去重复比较已经部分匹配的字符,比如序列“abcdabac”,如果“abcd”部分匹配了文本,而在接下来的“a”位置上不匹配,那么算法则会直接跳过4个位置,重新进行比较,而不是移位1个,...
        阅读全文
            
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.分析这就是字符串匹配算法算法一:brute forcetime complexity: O(nm)space complexity: O(1)12345...
        阅读全文
            
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may not...
        阅读全文
            
摘要:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263/** * Definition for singly-linked list. * struct ListNode { * int val; * L...
        阅读全文
            
摘要: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出...
        阅读全文
            
摘要: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:[ "((()))", "(()())", "(())()", "()(())", "...
        阅读全文
            
摘要: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...
        阅读全文
            
摘要: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 ...
        阅读全文
            
摘要: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...
        阅读全文
            
 
                    
                 浙公网安备 33010602011771号
浙公网安备 33010602011771号