Skip to content

Commit beb6a18

Browse files
refactor 849
1 parent ee52d5d commit beb6a18

File tree

1 file changed

+1
-28
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+1
-28
lines changed

src/main/java/com/fishercoder/solutions/_849.java

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
11
package com.fishercoder.solutions;
22

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-
* */
303
public class _849 {
314
public static class Solution1 {
325
int maxDist = 0;
33-
6+
347
public int maxDistToClosest(int[] seats) {
358
for (int i = 0; i < seats.length; i++) {
369
if (seats[i] == 0) {

0 commit comments

Comments
 (0)