Leetcode Practice
LC 3. Longest Substring Without Repeating Characters
- Last updated
- Reading time
- 1 min read
The problem
First Solution
function lengthOfLongestSubstring(s: string): number {
let currHash = {}
let answer = 0
let leftPointer = 0
for (let i = 0; i < s.length; i++) {
if (Number.isInteger(currHash[s[i]]) && currHash[s[i]] >= leftPointer) {
leftPointer = currHash[s[i]] + 1
}
answer = Math.max(answer, i + 1 - leftPointer)
currHash[s[i]] = i
}
return answer
}