003

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.

Subscribe to see which companies asked this question.


        //思路:a:第一个指针位置,目前开始判断,b:第二个位置,探测最长的长度
        //i:指针到b的时候,从a到b开始检测,是否有i=(a,b)之间相同,
        //如果出现不同或者i到了l-1的时候,开始进行判断:是否这个长度>max
   

实际问题:

对于菜鸡来说

要写一个逻辑

中间会有很多问题

然后再不断修bug

怎么样做快一点呢

第一个 背一种思路

缺点:太迂腐

第二种 有ide来编译

节约时间效率高

第三种 高手写的时候便能大致模拟,考虑各种bug的问题

最不推荐,瞎jb想,瞎调bug,并且走神,ruin 掉你的耐心

总而言之,

水平不够的情况下

已经没有精力去看其他的算法和语言了

-

这次运气还不错

错误一大堆


瞎搞得时候很快


准备下个xcode来调试

-----------------------------------------------------------------------------------------------------------------------


class Solution {

public:
    int lengthOfLongestSubstring(string s) {
        int l=s.length();
        int a,b,max=0,count=1;
        int c,d;//to mark
        if(l==1){
        return 1;


        }
        int be,ed;
        int i;//for move 
        a=0;
        while(a<l){
        for(b=a+1;b<l;b++){
       
        bool flag=true;
        for(i=a;i<b;i++){
        //cout<<"i:"<<i<<endl; 
        if(s[i]==s[b]){
        flag=false;
                        break;
        }
        }
        if(!flag||i==l-1){
       
        if(i==l-1&&flag)//last


        count++;
        if(count>max){
                        be=a;
                        if(flag)
                            ed=b;
                        else 
                            ed=b-1;
        max=count;
        c=a;
        d=b-1;
        }
        break;


        }
        count++;
        if(!flag)
        break;




        }
        
        //count end
        if(b==l-1||b==l)
        break;
        if(a==l-1)
            break;
        //cout<<i<<endl;
        a=i+1;//move to i+1
        count=1;
    }
return max;

    }




};
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值