《leetcode》longest-substring-without-repeating
来源:互联网 发布:mac怎么写java 编辑:程序博客网 时间:2024/06/05 11:17
题目描述
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for “abcabcbb” is “abc”, which the length is 3. For “bbbbb” the longest substring is “b”, with the length of 1.
解析:题目的意思是求最大不重复的连续的子串,注意字符不能再前面重复。
public class Solution { public int lengthOfLongestSubstring(String s) { int max=0; for(int i=0;i<s.length();i++){ int count=1;//当前字符计数1次 for(int j=i+1;j<s.length();j++){ int start=i; boolean flag=false; while (start<j){ if(s.charAt(j)==s.charAt(start)){ flag=true; break; } start++; } if(!flag){//在之前的字符串里没有出现过 count++; }else {//出现后就没必要继续了 break; } } if(count>=max){ max=count; } } return max; }}
阅读全文
0 0
- 《leetcode》longest-substring-without-repeating
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- chrome浏览器console拓展用法
- css3之关键帧的解说
- C#:DeviceNotifier USB设备插拔监听方法
- 隐式等待
- 正则表达式
- 《leetcode》longest-substring-without-repeating
- 关于昨天的并查集
- 独家:阿里巴巴DevOps落地实践玩法及思路解析
- \r,\n,\r\n的区别
- 各类数据类型变量的范围
- JQuery学习(一)
- 使用Visual Studio 2005开发的注意事项
- Android App 开发技能图谱
- 正确认识Docker、Kubernetes 、Apache Mesos