星空网 > 软件开发 > Java

3. Longest Substring Without Repeating Characters

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 }

 




原标题:3. Longest Substring Without Repeating Characters

关键词:string

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

lazada装修:https://www.goluckyvip.com/tag/85813.html
lazada手续费:https://www.goluckyvip.com/tag/85815.html
lazada账户:https://www.goluckyvip.com/tag/85816.html
lazada融资:https://www.goluckyvip.com/tag/85817.html
阿里lazada岗级:https://www.goluckyvip.com/tag/85818.html
阿里东南亚lazada:https://www.goluckyvip.com/tag/85819.html
滨州旅游景点哪儿好玩-滨州一日游必去的四大景点:https://www.vstour.cn/a/404241.html
青岛崂山旅游攻略自驾游(详细介绍崂山自驾游路线和景点):https://www.vstour.cn/a/404242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流