Skip to content

Commit

Permalink
logestsubstringwithoutrepeatingcharacters
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiezhu committed Mar 29, 2015
1 parent 580a39a commit a4aaa25
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jackiezhu;

/**
* Created by JackieZhu on 15/3/29.
*/
public class LongestSubstringWithoutRepeatingCharacters {
public int lengthOfLongestSubstring(String s) {
int []hash = new int[256];
int start = 0, end = 0, ret = 0;
while(end < s.length()) {
int c = s.charAt(end);
if(hash[c] == 0) {
hash[c] ++;
ret = Math.max(ret, end-start+1);
end ++;
} else {
hash[s.charAt(start)] --;
start ++;
}
}
return ret;
}
}
wqqsxq

0 comments on commit a4aaa25

Please sign in to comment.