码迷,mamicode.com
首页 >  
搜索关键字:median of two sor    ( 12209个结果
[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——
Add Two Numbers You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two...
分类:其他好文   时间:2014-06-11 00:35:15    阅读次数:243
【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: 2Sum/3Sum/3SumClosest/4Sum系列问题(转载)
转载:http://blog.csdn.net/li4951/article/details/8693212leetcode上有好几道关于数组中几个数据和为target的题目。恰好正在看剑指offer中“和为s的两个数组这章”,据此思想,leetcode上的三道题目都被我解决了。总结一下。1.two...
分类:其他好文   时间:2014-06-10 08:35:50    阅读次数:253
hust 1230 beautiful
题目描述Timy is visiting a beautiful park. There are M rivers and N lakes(marked 1-N), any two lakes are connected by at most one river. He knows that the...
分类:其他好文   时间:2014-06-09 20:57:26    阅读次数:259
[leetcode]Scramble String @ Python
原题地址:https://oj.leetcode.com/problems/scramble-string/题意:Given a strings1, we may represent it as a binary tree by partitioning it to two non-empty su...
分类:编程语言   时间:2014-06-09 19:02:59    阅读次数:197
[leetcode]Add Binary @ Python
原题地址:https://oj.leetcode.com/problems/add-binary/题意:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"...
分类:编程语言   时间:2014-06-08 20:28:04    阅读次数:300
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
[LeetCode] Two Sum [17]
题目 :Input: numbers={2, 7, 11, 15}, target=9 Output: index1=1, index2=2 解题思路: 给出一个数组合一个数,如果两个数的和等于所给的数,求出该两个数所在数组中的位置。 这个题也挺常见的,就是两个指针,从前后两个方向扫描。但是本题有以下几个需要的点: 1. 所给数组不是有序的; 2. 返回的下标是从1开始的,并且是原来无序数组中的下标; 3. 输入数组中可能含有重复的元素。 好了,把以上三点想到的话,做这个题应该不会有啥问题。 具体方法:把原...
分类:其他好文   时间:2014-06-08 02:14:06    阅读次数:250
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!