#3.Longest Substring Without Repeating Characters [LeetCode Grind 75 in Java]
[Problem Link] https://leetcode.com/problems/longest-substring-without-repeating-characters/
class Solution {
public int lengthOfLongestSubstring(String s) {
HashMap<Character , Integer> map = new HashMap<>();
int l = 0;
int ans = 0;
int n = s.length();
for(int r = 0 ; r < n ; r ++){
char c = s.charAt(r);
if(!map.containsKey(c) || map.get(c) < l){
map.put(c , r);
ans = Math.max(ans, r - l + 1);
}else{
l = map.get(c) + 1;
map.put(c , r);
}
}
return ans;
}
}