zoukankan      html  css  js  c++  java
  • merge-sorted-array


    /**
    * 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 to hold additional elements from B.
    * The number of elements initialized in A and B are m and n respectively.
    *
    * 给定两个排序整数数组A和B,将B合并为一个排序数组。
    * 注:
    * 您可以假定A有足够的空间容纳B中的附加元素。A和B中初始化的元素数分别为m和n。
    */

    import java.util.Arrays;
    
    /**
     * 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 to hold additional elements from B.
     * The number of elements initialized in A and B are m and n respectively.
     *
     * 给定两个排序整数数组A和B,将B合并为一个排序数组。
     * 注:
     * 您可以假定A有足够的空间容纳B中的附加元素。A和B中初始化的元素数分别为m和n。
     */
    
    public class Main43 {
        public static void main(String[] args) {
            int[] A = {1,2,3,2,4,3,5};
            Arrays.sort(A);
            for (int i=0;i<A.length;i++) {
                System.out.print(A[i] + ", ");
            }
        }
    
        public static void merge(int A[], int m, int B[], int n) {
            for (int i=0;i<n;i++) {
                A[m+i] = B[i];
            }
            Arrays.sort(A);
        }
    
    }
    

      

  • 相关阅读:
    Docker入门
    服务配置中心
    zuul网关
    git2
    git1
    git
    shiro授权、注解式开发
    shiro认证-SSM
    Shiro入门
    Springmvc之文件上传
  • 原文地址:https://www.cnblogs.com/strive-19970713/p/11325618.html
Copyright © 2011-2022 走看看