[LeetCode]Longest Substring Without Repeating Characters

来源:互联网 发布:java项目经理必备技能 编辑:程序博客网 时间:2024/06/14 18:23

题目:点击打开链接

public class Solution {    public int lengthOfLongestSubstring(String s) {        if (null == s) {            return 0;        }                int length = s.length();        if (1 >= length) {            return length;        }                int max = 0;        int count = 0;        int start = 0;        int index = 0;        for (index=0; index<length; index++) {            if (!(s.indexOf(s.charAt(index), start) == index)) {                count = index - start;                start = s.indexOf(s.charAt(index), start) + 1;                if (count > max) {                    max = count;                }            }        }                count = index - start;        if (count > max) {            max = count;        }                return max;    }}

0 0
原创粉丝点击