题目:
Given two sorted integer arrays A and B, merge B into A as one sorted array.
原题链接(点我)
解题思路:
合并两个数组为一个有序数组,这题也很简单,唯一考查的地方就是怎么处理数组,是从前往后还是从后往前。一般情况,从后往前的效率比从前往后高,也要省不少事。代码如下,从后开始合并。
代码实现:...
分类:
其他好文 时间:
2014-06-11 00:37:42
阅读次数:
314
几个实例展示python中数据结构list的魅力!
list变量申明
the_count = [1, 2, 3, 4, 5]
fruits = ['apples', 'oranges', 'pears', 'apricots']
change = [1, 'pennies', 2, 'dimes', 3, 'quarters']
访问list元素
array= [1,2,5,3,6,8...
分类:
编程语言 时间:
2014-06-11 00:16:28
阅读次数:
285
在我们开发过程中,判断数组为空时你会想到什么方法呢?首先想到的应该是empty函数,不过直接用empty函数判断为空是不对的,因为当这个值是多维数的时候,empty结果是有值的
其实我们可以利用array_filter函数轻松去掉多维空值,而数组的下标没有改变,下面是举例用法:...
分类:
Web程序 时间:
2014-06-10 13:59:37
阅读次数:
224
Find the contiguous subarray within an array
(containing at least one number) which has the largest sum.For example, given
the array[?2,1,?3,4,?1,2,1,...
分类:
其他好文 时间:
2014-06-10 09:14:50
阅读次数:
211
戳我去解题Given an array of strings, return all
groups of strings that are anagrams.Note: All inputs will be in
lower-case.Anagram(回文构词法)是指打乱字母顺序从而得到新的单词回文...
分类:
其他好文 时间:
2014-06-10 08:44:13
阅读次数:
275
戳我去解题Write a function to find the longest
common prefix string amongst an array of strings.class Solution {public: string
longestCommonPrefix(vecto...
分类:
其他好文 时间:
2014-06-10 08:29:55
阅读次数:
189
注意p的边界情况,p为0,或者 p为k奇数+偶数 = 奇数奇数+奇数 = 偶数#include
#include #include #include #include using namespace std;int main(){ int n,k,p;
long a; cin >>...
分类:
其他好文 时间:
2014-06-09 20:20:23
阅读次数:
243
//输出超过一半的数,如果没有则输出-1。通过编译,bymyselfimport
java.util.*;public class MoreThanHalf{ public static void main(String args[]){
int array[]={3,4,5,3...
分类:
其他好文 时间:
2014-06-09 19:32:47
阅读次数:
254
原题地址: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
原题地址:https://oj.leetcode.com/problems/first-missing-positive/题意:Given
an unsorted integer array, find the first missing positive integer.For
example,G...
分类:
编程语言 时间:
2014-06-09 17:44:43
阅读次数:
980