일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 디자인
- 프로그래머스
- wai-aria
- react
- 제로베이스 프론트엔드 스쿨
- 카드뉴스
- leetcode
- JavaScript
- TypeScript
- 알고리즘
- 비트연산자
- 정규표현식
- 웹접근성
- html&css
- programmers
- react-query
Archives
- Today
- Total
記錄
3. Longest Substring Without Repeating Characters 본문
문제 링크: https://leetcode.com/problems/longest-substring-without-repeating-characters/
난이도: Medium
Given a string s, find the length of the longest substring without repeating characters.
주어진 문자열 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.
Constraints:
- 0 <= s.length <= 5 * 104
- s consists of English letters, digits, symbols and spaces.
Related Topics: Hash Table, String, Sliding Window
문제풀이
var lengthOfLongestSubstring = function(s) {
//반복되지 않는 가장 긴 문자열
let k=0;
let maxl=0;
for (let i=0;i<s.length;i++){
for (let j=k;j<i;j++){
if (s[i]==s[j]){ //중복 문자를 만났을 때
k=j+1;//그 다음 문자(그 전은 안되니까 넘기고 break)
break;
}
}
//시작점 k, index+1
if (i-k+1>maxl){
maxl=i-k+1;
}
}
return maxl;
};
'FRONTEND STUDY > LeetCode' 카테고리의 다른 글
48. Rotate Image (0) | 2022.11.19 |
---|---|
28. Find the Index of the First Occurrence in a String (0) | 2022.10.28 |
20. Valid Parentheses (0) | 2022.10.25 |
120. Triangle (0) | 2022.10.24 |
[JS] 386. Lexicographical Numbers (0) | 2022.10.20 |
Comments