@TOC
# 一、合并两个有序的数组 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/0b0a4d6e9f2f4e5c837d79f305b4a0c9.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ```java public void merge(int[] nums1, int m, int[] nums2, int n) { int temp[] = new int[m + n]; int index = 0; int i = 0; int j = 0; while (i < m && j < n) { if (nums1[i] <= nums2[j]) temp[index++] = nums1[i++]; else temp[index++] = nums2[j++]; } for (; i < m; ) { temp[index++] = nums1[i++]; } for (; j < n; ) { temp[index++] = nums2[j++]; } //再把数组temp中的值赋给nums1 for (int k = 0; k < m + n; k++) { nums1[k] = temp[k]; } } ```
# 二、第一个错误版本 ![在这里插入图片描述](https://ucc.alicdn.com/images/user-upload-01/b2ef378e807641a4b92809c0ec093d0e.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAV1NLSDA5Mjk=,size_20,color_FFFFFF,t_70,g_se,x_16) ```java public int firstBadVersion(int n) { int min = 1, max = n; while (min < max) { int mid = min + (max - min) / 2; if (!isBadVersion(mid)){ min = mid + 1; }else{ max = mid; } } return min; } ```