【题解】【数组】【Leetcode】Merge Sorted Array
2014-02-01 13:06
495 查看
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 to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
思路:
归并的一部分,比Merge Two Sorted Lists还要简单
代码:
Note:
You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.
思路:
归并的一部分,比Merge Two Sorted Lists还要简单
代码:
void merge(int A[], int m, int B[], int n) { int i = m-1; int j = n-1; int t = m+n-1;//t不能定义在for循环内,否则最后无法访问 while(t>=0 && i>=0 && j>=0){ if(A[i] > B[j]) A[t--] = A[i--]; else A[t--] = B[j--]; } while(j >= 0) A[t--] = B[j--]; }
相关文章推荐
- Nginx初步-6:使用CUDA为PHP加速
- How to build monitoring system with Face Recognization by HTC Hero、VideoLAN and EmguCV.
- How to solve the Eclipse's endless "Subversion Connector Discovery" proglem
- 关于unity3d插件的自动打包
- BasicStroke参数详解[转]
- Titanium开发环境搭建第一个坑
- Theano学习三----Theano function
- 如何复制表结构、如何复制表数据:
- POJ 2752 kmp next数组理解
- Python聊天室程序---基础
- Android Bluetooth蓝牙开发\蓝牙协议\蓝牙通信例子_Android支持蓝牙4.0版本_BLE开发
- ARM、DSP、FPGA的技术特点和区别
- freopen
- droid gps开发必备资料(含测试demo下载) .
- 使用ant让Android自动打包的build.xml,自动生成签名的apk文件(支持android4.0以上的版本) .
- ood experience
- cocos2dx一些基本概念
- hdu 3746 kmp周期特性理解
- learning nodejs 2 - connect middleware
- Codeforces Round #226 (Div. 2)