码迷,mamicode.com
首页 >  
搜索关键字:problems    ( 6275个结果
61:Rotate List(旋转链表)【链表】【两指针】
题目链接:https://leetcode.com/problems/rotate-list//* 题意:给出一个链表,将链表向右旋转k个位置 *//** *思路:右旋k个位置,相当与将链表从第len-k个位置截断,然后 * 将两截链表交换位置,重新链接成一个链表 * */stru...
分类:其他好文   时间:2015-04-03 14:47:32    阅读次数:113
LeetCode69 Sqrt(x)
链接地址:https://leetcode.com/problems/sqrtx/ 这道题就是求一个数的平方根 我这里提供三种方法 1:大家都知道平方根一定都是[1,x/2]之间,所以从1循环到x/2, 但当x=1是通过的,不是好方法而且会TLE class Solution { // TLE而且不精确 public: int sqrt(int x) { in...
分类:其他好文   时间:2015-04-03 11:20:58    阅读次数:106
LeetCode4 Median of Two Sorted Arrays
题目地址:https://leetcode.com/problems/median-of-two-sorted-arrays/ 这道题就是求两个有序序列的中位数。这也是2015年4月阿里实习生招人附加题第一题 我用的是归并算法,时间复杂度和空间复杂度都为O(M+N) class Solution { public: double findMedianSortedArrays(int ...
分类:其他好文   时间:2015-04-03 11:18:54    阅读次数:134
Insert Interval
https://leetcode.com/problems/insert-interval/Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).Yo...
分类:其他好文   时间:2015-04-02 22:05:31    阅读次数:114
leetCode 101-Symmetric Tree
链接:https://leetcode.com/problems/symmetric-tree/ 此题就是判断一棵二叉树是否为对称二叉树,刚开始以为中序遍历输出,然后看是否是为回文字串,但是这种思路是错了,如[1,2,3,#,3,#,2]. 代码如下: 通过循环递归判断左孩子的左子树与右孩子的右子树 及 左孩子的右子树与右孩子的左子树即可得到结果。 class Solution { pub...
分类:其他好文   时间:2015-04-02 18:52:21    阅读次数:143
Merge Intervals
https://leetcode.com/problems/merge-intervals/Given a collection of intervals, merge all overlapping intervals.For example,Given[1,3],[2,6],[8,10],[15...
分类:其他好文   时间:2015-04-02 18:34:07    阅读次数:113
Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心)
The little girl loves the problems on array queries very much.One day she came across a rather well-known problem: you’ve got an array of n elements (the elements of the array are indexed starting from...
分类:其他好文   时间:2015-04-02 16:31:33    阅读次数:125
First Missing Positive
https://leetcode.com/problems/first-missing-positive/Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]...
分类:其他好文   时间:2015-04-02 14:57:32    阅读次数:139
leetCode 98-Validate Binary Search Tree
题目链接:https://leetcode.com/problems/validate-binary-search-tree/ 就是判断一个给定的二叉树是否为二叉查找树。 我的思路是:先将该树中序遍历一遍,按中序遍历的顺序保存到一个vector中,然后判断vector中的顺序即可。 代码: class Solution { public: void inOrder(TreeNode...
分类:其他好文   时间:2015-04-02 10:29:28    阅读次数:107
leetCode198-House Robber-状态压缩
链接:https://leetcode.com/problems/house-robber/ 这道理可以看做是状态压缩,每两个数字看做是一行,状态有3个,故需要F[N][3]的数组,F[i][j]就表示第i行状态j时rob的money。 具体状态压缩可以看我这两篇blog: 算法练习系列—hiho1048 状态压缩一(铺地砖)  算法练习系列—hiho1044 状态压缩二(捡垃圾) #inc...
分类:其他好文   时间:2015-04-01 20:03:09    阅读次数:166
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!