随笔分类 - Algorithm---Interview Set
摘要:Given a set of distinct integers,nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not...
阅读全文
摘要:【题目描述】有一个随机序列的数组,找到其中缺失的最小正整数举例如下,在[1, 2, 0] 中,该最小正整数应为3在[3, 4, -1, 1]中,该最小正整数应该为2【解题思路】如果允许开辟任意大小的空间,易得用桶的思想可以解决这题简单的说,开辟一个数组,从1扫过来如果不存在那么break输出即可如果...
阅读全文
摘要:使用归并排序对链表进行排序O(nlgn) 的时间效率/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : va...
阅读全文
摘要:Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two nu...
阅读全文
摘要:/************************************************************************* > File Name: code01.cpp > Author: Jeremy Wu > Created Time: Thu 04...
阅读全文
摘要:在数组中,对于所有元素,找出比当前元素大的下一个元素意思就是,eg. 数组为 3 1 2 5 4 6 7那么我们需要得到的结果应该是 5 2 5 6 6 7 -1解决方法如下:暴力匹配: O (n ^ 2 ) 的效率对所有元素匹配过去,效率非常的低经过提示, 我想到的一种 O ( nlg n...
阅读全文