标签:style class blog code java http
1 public class Solution { 2 public int lengthOfLongestSubstring(String s) { 3 int length = s.length(); 4 if (length == 0) return 0; 5 int begin = 0; 6 int end = 1; 7 int longest = 0; 8 int value = 0; 9 Hashtable<Integer, Character> checker = new Hashtable<Integer, Character>(); 10 while (end <= length) { 11 String temp = s.substring(begin, end); 12 if (isunique(temp, checker)) { 13 value = (int)(s.charAt(end-1) - ‘\0‘); 14 checker.put(value, s.charAt(end-1)); 15 end++; 16 longest++; 17 } 18 else { 19 checker.remove((int)(s.charAt(begin) - ‘\0‘)); 20 begin++; 21 end++; 22 } 23 } 24 return longest; 25 } 26 27 public boolean isunique(String str, Hashtable<Integer, Character> checker) { 28 char c = str.charAt(str.length() - 1); 29 if (checker.containsKey((int) c)) return false; 30 else return true; 31 } 32 }
Leetcode: Longest Substring Without Repeating Characters,布布扣,bubuko.com
Leetcode: Longest Substring Without Repeating Characters
标签:style class blog code java http
原文地址:http://www.cnblogs.com/EdwardLiu/p/3781137.html