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
- Binary Tree
- sorting
- hash table
- simulation
- Binary Search
- implement
- Math
- 구현
- two pointers
- Class
- Counting
- Number Theory
- geometry
- 파이썬
- Method
- java
- array
- Matrix
- SQL
- dynamic programming
- Tree
- string
- Data Structure
- greedy
- bit manipulation
- database
- 자바
- 코테
- 코딩테스트
- Stack
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1624. Largest Substring Between Two Equal Characters 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1624. Largest Substring Between Two Equal Characters
무지맘 2022. 12. 29. 12:251. Input
1) 문자열 s
2. Output
1) 같은 문자 2개 사이에 있는 substring중 가장 긴 것의 길이를 반환
2) 해당 substring이 없다면 –1을 반환
3. Constraint
1) 1 <= s.length <= 300
2) s는 영어 소문자로만 이루어져 있다.
4. Example
Input: s = "abca" -> Output: 2 (a 사이의 “bc”)
Input: s = "aa" -> Output: 0 (a 사이의 “”)
Input: s = "cbzxy" -> Output: -1 (같은 문자가 없음)
5. Code
1) 첫 코드(2022/08/01)
int max = -1;
for(int i=0 ; i<s.length()-1 ; i++){
char c = s.charAt(i);
for(int j=i+1 ; j<s.length() ; j++){
if(c==s.charAt(j)){
if(max<j-i-1) max = j-i-1;
}
}
}
return max;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 844. Backspace String Compare (0) | 2022.12.29 |
---|---|
[LeetCode/Easy] 1662. Check If Two String Arrays are Equivalent (0) | 2022.12.29 |
[LeetCode/Easy] 1619. Mean of Array After Removing Some Elements (0) | 2022.12.29 |
[LeetCode/Easy] 1608. Special Array With X Elements Greater Than or Equal X (0) | 2022.12.29 |
[LeetCode/Easy] 1614. Maximum Nesting Depth of the Parentheses (0) | 2022.12.29 |