Leetcode 3. Longest Substring Without Repeating Characters

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.

题目要求最长子串,但是不包含重复字符。
对字符串从左向右分析,依次寻找不包含重复字符的子串,统计出现的最大长度即可
C代码如下,已通过。

int lengthOfLongestSubstring(char* s) {
    int i=0,l=0,r=0,ans=0;
    while(s[r]!='\0')
    {
        for(i=l;i

你可能感兴趣的:(Leetcode 3. Longest Substring Without Repeating Characters)