public int lengthOfLongestSubstring(String s) {
		if (s == null || s.equals(""))
			return 0;
		if (s.length() == 1)
			return 1;
		int[] flag = new int[256];//store the last position of char(index) showing up
		Arrays.fill(flag, -1);
		flag[s.charAt(0)] = 0;
		int res = 0;
		int start = 0;
		for (int i = 1; i < s.length(); ++i) {
			if (flag[s.charAt(i)] >= start) {
				// case looks like st, ... pre, ... i, then start from p+1;
				res = Math.max(res, i - start);
				start = flag[s.charAt(i)] + 1;
			}
			res = Math.max(res, i - start + 1);
			flag[s.charAt(i)] = i;
		}
		return res;
	}