美文网首页工作生活
3 Longest Substring Without Repe

3 Longest Substring Without Repe

作者: 斌小斌 | 来源:发表于2019-07-01 23:37 被阅读0次

3 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

public int lengthOfLongestSubstring(String s) {
    char a[]=s.toCharArray();
    int result=0,flag=1;
    for(int i=0;i<a.length;i++){
        for(int j=0;j<i;j++){
            if(a[i]==a[j])
                flag=0;
        }
        if(flag==1){
            result++;
            }
        flag=1;
    }
    return result;
}

相关文章

网友评论

    本文标题:3 Longest Substring Without Repe

    本文链接:https://www.haomeiwen.com/subject/hzmocctx.html