给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
解题思路:使用queue的思想来解题;
class Solution { public int lengthOfLongestSubstring(String s) { int result = 0; char[] charList = s.toCharArray(); StringBuilder stringQueue = new StringBuilder(); for(int i = 0; i < s.length(); i++){ int index = stringQueue.toString().indexOf(charList[i]); if(index >= 0){ result = result > stringQueue.toString().length() ? result : stringQueue.toString().length(); if(index == 0){ stringQueue.deleteCharAt(0); }else { stringQueue.delete(0, index+1); } } stringQueue.append(charList[i]); } result = result > stringQueue.toString().length() ? result : stringQueue.toString().length(); return result; } }