每日一道算法题--leetcode 3--最长子串--C++

给定一个字符串,找出不含有重复字符的最长子串的长度。

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int slength=s.length();
        int maxlength=0;
        int currentlength=1;
        int i=0;
        int j=1;
        int same=0;
        int nowpoint=0;
        int lastlength=1;
        if(slength==1){
             maxlength=1;
        }else{
            while(j=i-lastlength+1;--nowpoint){
                if(s[j]==s[nowpoint]){
                    same=1;
                    break;
                }
            }
            if(same){
                 i=nowpoint+1;
                 j=i+1;
                 maxlength

 

你可能感兴趣的:(每日一道算法题,C++)