Skip to content

Commit fc6211f

Browse files
solves two furthest houses with different color
1 parent 11dbb09 commit fc6211f

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@
493493
| 2062 | [Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string) | [![Java](assets/java.png)](src/CountVowelSubstringsOfAString.java) | |
494494
| 2068 | [Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent) | [![Java](assets/java.png)](src/CheckWhetherTwoStringsAreAlmostEquivalent.java) | |
495495
| 2073 | [Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets) | [![Java](assets/java.png)](src/TimeNeededToBuyTickets.java) | |
496-
| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | | |
496+
| 2078 | [Two Furthest Houses With Different Colors](https://leetcode.com/problems/two-furthest-houses-with-different-colors) | [![Java](assets/java.png)](src/TwoFurthestHousesWithDifferentColors.java) | |
497497
| 2085 | [Count Common Words With One Occurrence](https://leetcode.com/problems/count-common-words-with-one-occurrence) | | |
498498
| 2089 | [Find Target Indices After Sorting Array](https://leetcode.com/problems/find-target-indices-after-sorting-array) | | |
499499
| 2094 | [Finding 3-Digit Even Numbers](https://leetcode.com/problems/finding-3-digit-even-numbers) | | |

Diff for: src/TwoFurthestHousesWithDifferentColors.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class TwoFurthestHousesWithDifferentColors {
2+
public int maxDistance(int[] colors) {
3+
int i = colors.length - 1;
4+
for ( ; i >= 0 && colors[i] == colors[0] ; i--);
5+
int distance = i;
6+
for (i = 0 ; i < colors.length && colors[i] == colors[colors.length - 1] ; i++);
7+
return Math.max(distance, colors.length - 1 - i);
8+
}
9+
}

0 commit comments

Comments
 (0)