package org.example.interview.practice;/** * @author xianzhe.ma * @date 2021/11/6 */public class NC_36_findMedianinTwoSortedAray { public int findMedianinTwoSortedAray (int[] arr1, int[] arr2) { // write code here int finalPos = arr1.length; int firstIndex = 0; int secOndIndex= 0; if (finalPos == 1) { return Math.min(arr1[0], arr2[0]); } int tag = -1;//0 first 1 second while (firstIndex + secondIndex < finalPos) { if (arr1[firstIndex] <= arr2[secondIndex]) { firstIndex++; tag = 0; } else { secondIndex++; tag = 1; } } if (tag == 0) { return arr1[firstIndex-1]; } else { return arr2[secondIndex-1]; } }}
package org.example.interview.practice;import java.util.ArrayList;import java.util.Comparator;/** * @author xianzhe.ma * @date 2021/7/27 */public class NC_37_MERGEINTERVAL { public static class Interval { int start; int end; Interval() { start = 0; end = 0; } Interval(int s, int e) { start = s; end = e; } } public ArrayList merge(ArrayList intervals) { intervals.sort(new Comparator() { @Override public int compare(Interval o1, Interval o2) { return o1.start - o2.start; } }); ArrayList ans = new ArrayList(); int len = intervals.size(); if (len == 0) return ans; for (int i = 1; i