public int lengthOfLongestSubstring(String s) {
		int longest, mindex, n = s.length(), startindex = 0, endindex = 1, lastindex;
		int[] map = new int[26];
		char[] c = s.toCharArray();
		if (n == 0) {
			return 0;
		} else {
			longest = 1;
		}

		for (int m = 0; m < 26; m++) {
			map[m] = -1;
		}

		while (startindex < n - 1) {
			map[c[startindex] - 'a'] = startindex;
			// System.out.println(startindex);
			while (endindex < n) {
				mindex = c[endindex] - 'a';
				lastindex = map[mindex];
				if (lastindex != -1) {
					if (longest < endindex - startindex) {
						longest = endindex - startindex;
						// startindex = lastindex + 1;
					}
					for (int i = startindex; i <= lastindex; i++) {
						map[c[i] - 'a'] = -1;
					}
					startindex = lastindex + 1;
					map[mindex] = endindex;
					endindex++;
				} else {
					map[c[endindex] - 'a'] = endindex;
					endindex++;
				}
			}
			if (endindex == n) {
				return longest <= endindex - startindex ? endindex - startindex
						: longest;
			}
		}
		return longest;
	}