博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[LeetCode]Merge Sorted Array
阅读量:4150 次
发布时间:2019-05-25

本文共 885 字,大约阅读时间需要 2 分钟。

class Solution {//write down some cases and find out the regular patternpublic:	void merge(int A[], int m, int B[], int n) {		// Start typing your C/C++ solution below		// DO NOT write int main() function		int i = m-1;		int j = n-1;		int now = m+n-1;		while(i >= 0 && i < m && j >= 0 && j < n)		{			if(A[i] > B[j])				A[now--] = A[i--];			else A[now--] = B[j--];		}		while (j >= 0 && j < n)			A[now--] = B[j--];	}};

second time

class Solution {public:    void merge(int A[], int m, int B[], int n) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        int end = m+n-1;        int i = m-1;        int j = n-1;        while(i >= 0 && j >= 0 && end >= 0)        {            if(A[i] >= B[j]) A[end--] = A[i--];            else A[end--] = B[j--];        }        while(i >= 0) A[end--] = A[i--];        while(j >= 0) A[end--] = B[j--];    }};

转载地址:http://hlxti.baihongyu.com/

你可能感兴趣的文章
什么是内存泄露,如何避免内存泄露 C++
查看>>
栈和堆的空间大小 C++
查看>>
什么是缓冲区溢出 C++
查看>>
sizeof C++
查看>>
使用指针有哪些好处? C++
查看>>
引用还是指针?
查看>>
checkio-non unique elements
查看>>
checkio-medium
查看>>
checkio-house password
查看>>
checkio-moore neighbourhood
查看>>
checkio-the most wanted letter
查看>>
Redis可视化工具
查看>>
大牛手把手带你!2021新一波程序员跳槽季,全套教学资料
查看>>
Guava Collections API学习之AbstractMapBasedMultimap
查看>>
Guava Collections API学习之HashBiMap
查看>>
Guava Collections API学习之Bimap
查看>>
Guava Collections API学习之Multisets
查看>>
Guava API学习之Resources
查看>>
Guava API学习之CharSequenceReader
查看>>
Guava API学习之Range
查看>>