码迷,mamicode.com
首页 > 其他好文 > 详细

Leetcode: Longest Substring Without Repeating Characters

时间:2014-06-13 08:31:32      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

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

标签:style   class   blog   code   java   http   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!