星空网 > 软件开发 > 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/84937.html
lazada估值:https://www.goluckyvip.com/tag/84938.html
lazada代打包:https://www.goluckyvip.com/tag/84939.html
参与条件:https://www.goluckyvip.com/tag/8494.html
lazada越南站点:https://www.goluckyvip.com/tag/84940.html
lazada购买流程:https://www.goluckyvip.com/tag/84941.html
桂林酒店销售多少钱 桂林旅游宾馆价格:https://www.vstour.cn/a/410227.html
十里银滩旅游攻略玩什么住哪里怎么去?:https://www.vstour.cn/a/410228.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流