题目 in a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. there is at least one empty seat, and at least one person sitting. alex wants to sit in the seat s ch that the distance between him and the closest person to him is maximized. ret rn that maxim m distance to closest person. example 1: inp t: [1,0,0,0,1,0,1] o tp t: 2 explanation: if alex sits in the second open seat (seats[2]), then the closest person has distance 2. if alex sits in any other open seat, the closest person has distance 1. th s, the maxim m distance to the closest person is 2. example 2: inp t: [1,0,0,0] o tp t: 3 explanation: if alex sits in the last seat, the closest person is 3 seats away. this is the maxim m distance possible, so the answer is 3. 答案 class sol tion { p blic int maxdisttoclosest(int[] seats) { int n = seats.length; int left_one_idx = -1, right_one_idx = n; int left = 0, right = n - 1; int[] arr1 = new int[n]; int[] arr2 = new int[n]; while(left  n) { if(seats[left] == 1) { arr1[left] = 0; left_one_idx = left; } else { if(left_one_idx == -1) arr1[left] = integer.max_value; else arr1[left] = left - left_one_idx; } if(seats[right] == 1) { arr2[right] = 0; right_one_idx = right; } else { if(right_one_idx == n) arr2[right] = integer.max_value; else arr2[right] = right_one_idx - right; } left; right--; } int max = integer.min_value; for(int i = 0; i  n; i) { int min = math.min(arr1[i], arr2[i]); if(min  max) max = min; } ret rn max;