3. 중복 문자 없는 가장 긴 부분 문자열 | LeetCode | Top Interview 150 | Coding Questions

발행: (2026년 1월 3일 오전 05:57 GMT+9)
1 분 소요
원문: Dev.to

Source: Dev.to

문제

솔루션

class Solution {
    public int lengthOfLongestSubstring(String s) {

        Map map = new HashMap<>();
        int left = 0;
        int maxLength = 0;

        for (int right = 0; right < s.length(); right++) {
            char ch = s.charAt(right);

            if (map.containsKey(ch)) {
                left = Math.max(left, map.get(ch) + 1);
            }

            map.put(ch, right);
            maxLength = Math.max(maxLength, right - left + 1);
        }

        return maxLength;
    }
}
Back to Blog

관련 글

더 보기 »

1390. 네 개의 약수

문제 설명: 정수 배열 nums가 주어지면, 해당 배열에서 정확히 네 개의 약수를 갖는 정수들의 약수 합을 반환한다. 그런 수가 없으면...