首页 > 其他 > 详细

Leetcode: Longest Substring Without Repeating Characters

时间:2014-06-13 08:30:52      阅读:368      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 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 }
bubuko.com,布布扣

 

Leetcode: Longest Substring Without Repeating Characters,布布扣,bubuko.com

Leetcode: Longest Substring Without Repeating Characters

原文:http://www.cnblogs.com/EdwardLiu/p/3781137.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!