class Solution {
public int lengthOfLongestSubstring(String s) {
Set<Character> ch = new HashSet<Character>();
int result = 0;
int st = 0, en = 0;
while (st < s.length() && en < s.length()) {
if (!ch.contains(s.charAt(en))) {
ch.add(s.charAt(en));
en++;
result = Math.max(result, en - st);
} else {
ch.remove(s.charAt(st));
st++;
}
}
return result;
}
}
Runtime: 6 ms, faster than 68.32% of Java online submissions for Longest Substring Without Repeating Characters.
Memory Usage: 39.2 MB, less than 56.34% of Java online submissions for Longest Substring Without Repeating Characters.
하나하나씩 영역확장해나가는~ 그런느낌