Skip to content

Commit 9d7c3e6

Browse files
authored
Create Two Furthest Houses With Different Colors.java
1 parent 5a23685 commit 9d7c3e6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int maxDistance(int[] colors) {
3+
int startIdx = 0;
4+
int endIdx = colors.length - 1;
5+
while (colors[0] == colors[endIdx]) {
6+
endIdx--;
7+
}
8+
while (colors[colors.length - 1] == colors[startIdx]) {
9+
startIdx++;
10+
}
11+
return Math.max(colors.length - 1 - startIdx, endIdx);
12+
}
13+
}

0 commit comments

Comments
 (0)