码迷,mamicode.com
首页 >  
搜索关键字:sorted    ( 5925个结果
Remove Duplicates from Sorted List
题目 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 方法 遍...
分类:其他好文   时间:2014-06-11 00:41:44    阅读次数:207
[LeetCode] Merge Sorted Array [22]
题目: Given two sorted integer arrays A and B, merge B into A as one sorted array. 原题链接(点我) 解题思路: 合并两个数组为一个有序数组,这题也很简单,唯一考查的地方就是怎么处理数组,是从前往后还是从后往前。一般情况,从后往前的效率比从前往后高,也要省不少事。代码如下,从后开始合并。 代码实现:...
分类:其他好文   时间:2014-06-11 00:37:42    阅读次数:314
【leetcode】Remove Duplicates from Sorted Array
int removeDuplicates(int A[], int n) { if(n <= 1) return n; int newIndex = 0; for(int i = 1; i < n; ++i){ if(A[i] != A[newIndex]) A[++newIndex] ...
分类:其他好文   时间:2014-06-10 10:57:49    阅读次数:131
【leetcode】Merge Two Sorted Lists
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.水题不解释,一A,...
分类:其他好文   时间:2014-06-10 08:58:37    阅读次数:191
【leetcode】Convert Sorted List to Binary Search Tree
问题: 给定一个有序链表,生成对应的平衡二叉搜索树。 分析 见Convert Sorted Array to Binary Search Tree 实现: TreeNode *buildTree(ListNode* head, ListNode *end){ if(head == NULL || head == end) return NULL; ...
分类:其他好文   时间:2014-06-10 07:17:29    阅读次数:264
[leetcode]Search in Rotated Sorted Array @ Python
原题地址:https://oj.leetcode.com/problems/search-in-rotated-sorted-array/题意:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e...
分类:编程语言   时间:2014-06-09 18:43:14    阅读次数:273
LEETCODE--Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3-...
分类:其他好文   时间:2014-06-08 21:56:41    阅读次数:297
[leetcode]Search for a Range @ Python
原题地址:https://oj.leetcode.com/problems/search-for-a-range/题意:Given a sorted array of integers, find the starting and ending position of a given target ...
分类:编程语言   时间:2014-06-08 21:03:21    阅读次数:297
Merge Sorted Array
题目 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional el...
分类:其他好文   时间:2014-06-08 05:05:47    阅读次数:268
[LeetCode] Median of Two Sorted Arrays [16]
求两个排序数组的中位数。这个题可以有以下几个思路: 首先可以想到的是将两个数组merge起来,然后返回其中位数。 第二个是,类似merge的思想加上计数,找到(m+n)/2个数或者其前后的数,这个就可以算出中位数。这个方法对于各种情况需要一一考虑到。 第三个,假设A[k/2-1]<B[k/2-1],那么A[k/2-1]之前的数一定在整个有序数列中(m+n)/2之前。 这里我给出后面两种思路的代码。 代码一( 思路三)...
分类:其他好文   时间:2014-06-08 03:44:47    阅读次数:231
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!