일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 홀리데이익스프레스
- 티스토리챌린지
- 자바스크립트
- 크리스마스
- 쿠킹덤
- Eclipse
- programmers
- 딥러닝
- oracle
- 개발자
- MySQL
- 노마드코더
- 자바
- edwith
- 웹개발
- 쿠킹덤공략
- 오블완
- HTML
- Java
- 쿠키런킹덤크리스마스
- 쿠키런킹덤
- 이클립스
- Spring
- 쿠키런킹덤공략
- SQL
- JavaScript
- dart
- 유니티
- Unity
- 프로그래머스
Archives
- Today
- Total
Dev study and notes
리트코드 0003 중복되지 않는 가장 긴 부분 문자열 찾기 LEETCODE 3. Longest Substring Without Repeating Characters 본문
LEETCODE
리트코드 0003 중복되지 않는 가장 긴 부분 문자열 찾기 LEETCODE 3. Longest Substring Without Repeating Characters
devlunch4 2024. 12. 3. 17:59반응형
3. 중복되지 않는 가장 긴 부분 문자열 찾기
3. Longest Substring Without Repeating Characters
Difficulty | Topics | Hints | URL |
---|---|---|---|
Easy | Hash_Table String Sliding_Window |
1 | https://leetcode.com/problems/longest-substring-without-repeating-characters/description/ |
Table of Contents
설명
문자열 s
가 주어졌을 때, 중복된 문자가 없는 가장 긴 부분 문자열의 길이를 구하세요.
예제
Example 1:
Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: s = "bbbbb" Output: 1 Explanation: The answer is "b", with the length of 1.
Example 3:
Input: s = "pwwkew" Output: 3 Explanation: The answer is "wke", with the length of 3. Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
제약 사항:
0 <= s.length <= 5 * 104
s
는 영어 대소문자, 숫자, 기호 및 공백으로 이루어져 있습니다.
Solutions
JAVA
class Solution {
public int lengthOfLongestSubstring(String s) {
Set<Object> set = new HashSet<>();
int strLength = s.length();
int begin = 0;
int end = 0;
int res = 0;
while (end < strLength) {
if (set.contains(s.charAt(end))) {
set.remove(s.charAt(begin++));
} else {
set.add(s.charAt(end++));
res = Math.max(res, end - begin);
}
}
return res;
}
}
반응형
'LEETCODE' 카테고리의 다른 글
리트코드 0002 두 수 더하기 LEETCODE 2. Add Two Numbers (0) | 2024.12.03 |
---|---|
리트코드 0001 두 수의 합 LEETCODE 1. Two Sum (0) | 2024.12.02 |
LEETCODE 0001 TWO SUM (0) | 2024.12.02 |
Comments