紧急Java练习 leetcode3. 无重复字符的最长子串

    技术2022-08-31  78

    class Solution { public int lengthOfLongestSubstring(String s) { int len_s = s.length(); if(len_s == 0){ return 0; } int head = 0; int tail = 1; int res = 1; while(tail < len_s){ int find = s.substring(head,tail).indexOf(s.charAt(tail)); if(find >= 0){ head = head + find + 1; } tail += 1; if(tail - head > res){ res = tail - head; } } return res; } }

     

    Processed: 0.011, SQL: 9