File tree 1 file changed +1
-28
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +1
-28
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 849. Maximize Distance to Closest Person
5
- *
6
- * In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty.
7
- * There is at least one empty seat, and at least one person sitting.
8
- * Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized.
9
- * Return that maximum distance to closest person.
10
- *
11
- * Example 1:
12
- * Input: [1,0,0,0,1,0,1]
13
- * Output: 2
14
- * Explanation:
15
- * If Alex sits in the second open seat (seats[2]), then the closest person has distance 2.
16
- * If Alex sits in any other open seat, the closest person has distance 1.
17
- * Thus, the maximum distance to the closest person is 2.
18
- *
19
- * Example 2:
20
- * Input: [1,0,0,0]
21
- * Output: 3
22
- * Explanation:
23
- * If Alex sits in the last seat, the closest person is 3 seats away.
24
- * This is the maximum distance possible, so the answer is 3.
25
- * Note:
26
- *
27
- * 1 <= seats.length <= 20000
28
- * seats contains only 0s or 1s, at least one 0, and at least one 1.
29
- * */
30
3
public class _849 {
31
4
public static class Solution1 {
32
5
int maxDist = 0 ;
33
-
6
+
34
7
public int maxDistToClosest (int [] seats ) {
35
8
for (int i = 0 ; i < seats .length ; i ++) {
36
9
if (seats [i ] == 0 ) {
You can’t perform that action at this time.
0 commit comments