LeetCode题解:Merge Sorted Array
2015-08-28 10:27
295 查看
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
题意:合并两个有序数组,数组1拥有足够的空间存储合并数组
解决思路:按序添加呗,从后向前添加
代码:
Note:
You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2. The number of elements initialized in nums1 and nums2 are m and n respectively.题意:合并两个有序数组,数组1拥有足够的空间存储合并数组
解决思路:按序添加呗,从后向前添加
代码:
public class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { while(n > 0){ nums1[m + n - 1] = nums1[m - 1] > nums2[n - 1]? nums1[--m] : nums2[--n]; } } }
相关文章推荐
- POJ 3046 Ant Counting
- 堆表修改内幕
- WSGI简介
- hdu1754-I Hate It(线段树)
- spring mvc
- 买点已现!阅兵前线指挥车同款电视降价大促
- 找出数组中重复的数
- win10平板模式中的的触摸键盘怎么打开?
- ffmpeg_struct: AVSampleFormat
- jQuery EasyUI和PHP实现数据的CURD操作
- Linux的tail 命令
- [刷题]Insertion Sort List
- Struts – MappingDispatchAction Example
- IMX6Solo启动流程-从Uboot到kernel 中
- linux shell 快捷键
- Windows Server 2008 如何部署Domain Controller
- Spring MVC入门案例(1)
- UVA - 1279 Asteroid Rangers (动点的最小生成树)
- [CareerCup] 7.1 Basketball Shooting Game 投篮游戏
- PHP中使用CURL实现GET和POST请求