Using Bubble Sort


  • 0
    A

    class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {

       for(int i=0;i<n;i++) {
       nums1[m+i]=nums2[i];  
       }
        
    int temp = 0;
    for (int i = 0; i < m+n; i++) {
        for (int j = 1; j < (m+n-i); j++) {
                if (nums1[j - 1] > nums1[j]) {
                temp = nums1[j - 1];
                nums1[j - 1] = nums1[j];
                nums1[j] = temp;
            }
        }
    }
        
              for(int i=0;i<m+n;i++){
               System.out.println(nums1[i]);
            }
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.