Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- SQL
- bit manipulation
- 코딩테스트
- simulation
- implement
- Tree
- java
- string
- array
- 파이썬
- Data Structure
- Class
- dynamic programming
- two pointers
- hash table
- Matrix
- 자바
- geometry
- Counting
- Stack
- database
- Math
- 코테
- Binary Tree
- Method
- Number Theory
- 구현
- Binary Search
- greedy
- sorting
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2078. Two Furthest Houses With Different Colors 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2078. Two Furthest Houses With Different Colors
무지맘 2023. 4. 26. 19:571. Input
1) int[] colors
- colors[i] == i번째 집의 색을 나타내는 숫자
2. Output
1) 색이 다른 집의 거리 차의 최댓값을 반환
- 거리 >= 0이므로 반환 값도 0 이상이다.
3. Constraint
1) n == colors.length
2) 2 <= n <= 100
3) 0 <= colors[i] <= 100
4) 테스트 케이스에는 반드시 색이 다른 집이 최소 2개 있다.
4. Example
Input: colors = [1,8,3,8,3] -> Output: 4
설명: 0번째와 4번째가 가장 멀다.
5. Code
1) 첫 코드(2023/04/26)
class Solution {
public int maxDistance(int[] colors) {
int max = 0;
for(int i=0 ; i<colors.length-1 ; i++)
for(int j=i+1 ; j<colors.length ; j++)
if(colors[i]!=colors[j])
max = Math.max(j-i, max);
return max;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2032. Two Out of Three (0) | 2023.04.27 |
---|---|
[LeetCode/Easy] 2094. Finding 3-Digit Even Numbers (0) | 2023.04.26 |
[LeetCode/Easy] 2073. Time Needed to Buy Tickets (0) | 2023.04.26 |
[LeetCode/Easy] 2053. Kth Distinct String in an Array (0) | 2023.04.26 |
[LeetCode/Easy] 2047. Number of Valid Words in a Sentence (0) | 2023.04.26 |