• 문제 링크
Longest Substring Without Repeating Characters - LeetCode
Can you solve this real interview question? Longest Substring Without Repeating Characters - Given a string s, find the length of the longest substring without duplicate characters. Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "
leetcode.com
• 풀이 코드
public class Solution {
public int lengthOfLongestSubstring(String s) {
boolean[] arr = new boolean[256];
int r = 0, l = 0, max = 0, n = s.length();
while (r < n) {
if (!arr[s.charAt(r)]) {
arr[s.charAt(r++)] = true;
max = Math.max(max, r - l);
} else arr[s.charAt(l++)] = false;
}
return max;
}
}'Problem Solving > LeetCode' 카테고리의 다른 글
| [LeetCode] 12. Integer to Roman - Java (0) | 2026.05.09 |
|---|---|
| [LeetCode] 11. Container With Most Water - Java (0) | 2026.05.08 |
| [LeetCode] 9. Palindrome Number - Java (0) | 2026.05.07 |
| [LeetCode] 2. Add Two Numbers - Java (0) | 2026.05.05 |
| [LeetCode] 1. Two Sum - Java (0) | 2026.05.04 |
댓글