博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeeCode 88. Merge Sorted Array两种解法
阅读量:4185 次
发布时间:2019-05-26

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

// Author : yqtao// Date   : 2016-7-6// Email  : yqtao@whu.edu.cn/************************************************************************************ 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 elements from B. The number of elements initialized in A and B*   are m and n respectively.***********************************************************************************/#include
#include
using namespace std;//Solutins 1: 4msvoid merge(vector
& nums1, int m, vector
& nums2, int n) { int i = 0, j = 0, k = 0; vector
temp(nums1.begin(), nums1.end()); //using a vector to restore nums1, while (i
& nums1, int m, vector
& nums2, int n) { int i = m - 1, j = n - 1, tar = m + n - 1; //from end to head while (j >= 0) { nums1[tar--] = i >= 0 && nums1[i] > nums2[j] ? nums1[i--] : nums2[j--]; }}

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

你可能感兴趣的文章
镜像文件
查看>>
苹果笔记本桌面下面的工具栏没了怎么调出来
查看>>
CSS原理与CSS经验分享
查看>>
oracle中int与number的区别
查看>>
php不用jsonp也能跨域
查看>>
solr作为一种开源的搜索服务器
查看>>
Pig分析数据过程
查看>>
linux下文件夹的创建、复制、剪切、重命名、清空和删除命令
查看>>
pentaho套件
查看>>
软件产品经理职责
查看>>
Linux下Tomcat的安装配置
查看>>
UI即User Interface
查看>>
大数据要学习知识
查看>>
Elasticsearch Java API总汇
查看>>
SearchRequestBuilder常用方法说明
查看>>
为什么有的程序员的代码结构混乱
查看>>
查看数据库
查看>>
SQLite 数据库
查看>>
行业应用
查看>>
工作的常识
查看>>