题解 | #合并两个有序的数组#
合并两个有序的数组
http://www.nowcoder.com/practice/89865d4375634fc484f3a24b7fe65665
归并排序
class Solution {
public:
void merge(int A[], int m, int B[], int n) {
int temp_result[m+n];
int current_inadex = 0;
int i = 0;
int j = 0;
while(i< m&&j<n){
if(A[i] < B[j]){
temp_result[current_inadex++] = A[i++];
}else{
temp_result[current_inadex++] = B[j++];
}
}
for(;i<m;){
temp_result[current_inadex ++ ] = A[i++];
}
for(;j<n;){
temp_result[current_inadex ++ ] = B[j++];
}
for(int i = 0; i< m+n;i++){
A[i] = temp_result[i];
}
}
};算法解析 文章被收录于专栏
这里主要是算法岗的自我思路总结
查看10道真题和解析