Advertisement
lazar955

Untitled

Oct 24th, 2023
1,077
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.41 KB | None | 0 0
  1. func lengthOfLongestSubstring(s string) int {
  2.     l:=0
  3.     res:=0
  4.     set:=map[byte]bool{}
  5.    
  6.     for r,_:= range s {
  7.         _,f:=set[s[r]]
  8.         for f {
  9.             delete(set,s[l])
  10.             l++
  11.               _,f=set[s[r]]
  12.         }
  13.         set[s[r]] = true
  14.         res = max(res,r - l + 1)
  15.     }
  16.     return res
  17. }
  18. func max(l,r int) int {
  19.     if l > r {
  20.         return l
  21.     }
  22.     return r
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement