首页 > 其他 > 详细

LeetCode - Longest Substring Without Repeating Characters

时间:2017-07-12 13:03:13      阅读:287      评论:0      收藏:0      [点我收藏+]

题目描述:

 找出一个字符串中,不含有相同字符的最长子串。

做法:

 开一个200的bool数组标记,Ascll码 是否已经出现过了。遍历即可。

AC代码:

class Solution {
      int a[200];
public:
    int lengthOfLongestSubstring(string s) {
 
        int l = 0;int r =0;
        int vmax = 0;
        while(s[r]){
            a[s[r]]++;
            while(a[s[r]]==2){
                a[s[l]]--;
                l++;
            }
            vmax = max(vmax,r-l+1);
            r++;
        }
        return vmax;
    }
};
983 / 983 test cases passed.
Status: Accepted
Runtime: 22 ms

LeetCode - Longest Substring Without Repeating Characters

原文:http://www.cnblogs.com/clover-xuqi/p/7154773.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!