SHARE
TWEET

Untitled

a guest Dec 15th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public int lengthOfLongestSubstring(String s) {
  3.        
  4.         Map<Character, Integer> map = new HashMap<>();
  5.        
  6.         int l = 0;
  7.         int r = 0;
  8.         int max = 0;
  9.         char c ;
  10.         //" "
  11.         while(r < s.length()){
  12.             c = s.charAt(r); //a
  13.             if(map.containsKey(c) && map.get(c) >=  l){
  14.                 max = Math.max(r-l, max); // 3
  15.                 l =  map.get(c) + 1; // 1
  16.             }        
  17.             map.put(c, r);    //{a=t}
  18.             r++;
  19.         }
  20.        
  21.         return Math.max(max, r-l);
  22.        
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top