LeetCode Merge Sorted Array

BabbleDay posted @ 2015年7月17日 03:02 in 刷题防身 with tags LeetCode Merge Sorted Array Java , 455 阅读

心得:编程语言随机应变= =

 

public class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int l = m + n - 1;
        int a = m-1;
        int b = n-1;
        int i=l;
        while(i>=0){
            if(a<0) nums1[i--] = nums2[b--];
            else if(b<0) nums1[i--] = nums1[a--];
            else if(nums1[a]>nums2[b]) nums1[i--] = nums1[a--];
            else nums1[i--] = nums2[b--];
        }
    }
}
Avatar_small
net worth 说:
2023年12月06日 22:05

Not everyone knows all information about a celebrity and their net worth which changes every day according to their fame and investment but you can follow the info on idol net worth which is available for everyone.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter