(5) Longest Substring Without Repeating Characters - LeetCode
Longest Substring Without Repeating Characters - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
접근 : 구현, 문자열
Javascript
let input = require("fs")
.readFileSync("input.txt") //"/dev/stdin"
.toString()
.split("\n")
.map((val) => val.trim());
function solution(input) {
//input
let s = input[0];
//Submit
s = s.split("");
let len = s.length;
let max = 0;
for (let i = 0; i < len; i++) {
let temp = [s[i]];
for (let j = i + 1; j < len; j++) {
if (temp.includes(s[j])) {
break;
} else {
temp.push(s[j]);
}
}
max = Math.max(max, temp.length);
}
console.log(max);
}
solution(input);
'코딩테스트(알고리즘) > leetCode' 카테고리의 다른 글
[leetCode] 819. Most Common Word (Javascript,Python) (0) | 2023.03.26 |
---|---|
[leetCode] 125. Valid Palindrome (Javascript) (0) | 2022.06.25 |
[leetCode] 11. Container With Most Water (Javascript) (0) | 2022.06.25 |
[leetCode] 1. Two Sum (Javascript) (0) | 2022.06.25 |
[leetCode] 13.Roman to Integer (Javascript) (0) | 2022.06.24 |