tanchukw

Untitled

Sep 2nd, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {
  4.         --m;
  5.         --n;
  6.         for (int i = m + n + 1; i >= 0; --i)
  7.         {
  8.             if (m >= 0 && (n < 0 || nums1[m] > nums2[n]))
  9.             {
  10.                 nums1[i] = nums1[m];
  11.                 --m;
  12.             }
  13.             else
  14.             {
  15.                 nums1[i] = nums2[n];
  16.                 --n;
  17.             }
  18.         }
  19.     }
  20. };
Advertisement
Add Comment
Please, Sign In to add comment