Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer ...
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb"
, the answer is "abc"
, which the length is 3.
Given "bbbbb"
, the answer is "b"
, with the length of 1.
Given "pwwkew"
, the answer is "wke"
, with the length of 3. Note that the answer must be a substring, "pwke"
is a subsequence and not a substring.
代码如下:
1 public class Solution { 2 public int lengthOfLongestSubstring(String s) { 3 int max=0; 4 char[] ss=s.toCharArray(); 5 6 for(int i=0;i<ss.length;i++) 7 { 8 int count=0; 9 Map<Character,Character> map=new HashMap<>();10 for(int j=i;j<ss.length;j++)11 {12 if(!map.containsKey(ss[j]))13 {14 map.put(ss[j],ss[j]);15 count++;16 } 17 else break;18 }19 if(count>max)20 max=count;21 }22 return max;23 }24 }
海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com
原标题:3. Longest Substring Without Repeating Characters
关键词:string
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。