File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
bytedance/longest_substring_without_repeating_characters Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 113113 - [ 225. 用队列实现栈] ( ./src/leetcode/design/leet_zh_225/MyStack.java )
114114 - [ 232. 用栈实现队列] ( ./src/leetcode/design/leet_zh_232/MyQueue.java )
115115
116+ - 【专项】
117+ - 【ByteDance】
118+ - [ 无重复字符的最长子串] ( ./src/leetcode/specialized/bytedance/longest_substring_without_repeating_characters/Solution.java )
119+
116120#### LeetCode 周赛
117121
118122- 【第 129 周】[ 题目链接] ( https://leetcode-cn.com/contest/weekly-contest-129 )
Original file line number Diff line number Diff line change 1+ ## 专项
Original file line number Diff line number Diff line change 1+ package leetcode .specialized .bytedance .longest_substring_without_repeating_characters ;
2+
3+ import java .util .HashMap ;
4+ import java .util .Map ;
5+
6+ public class Solution {
7+ /*
8+ * 无重复字符的最长子串
9+ * link: https://leetcode-cn.com/explore/interview/card/bytedance/242/string/1012
10+ * Label: 滑动窗口、hashMap、双指针
11+ *
12+ * 执行用时 : 8 ms
13+ * 内存消耗 : 40.4 MB
14+
15+ * */
16+ public int lengthOfLongestSubstring (String s ) {
17+ int maxLength = 0 ;
18+ if (s .length () == 0 ) {
19+ return maxLength ;
20+ }
21+
22+ char a ;
23+ int start , index ;
24+ start = 0 ;
25+ Map <Character , Integer > tmp = new HashMap <>();
26+ for (int i = 0 ; i < s .length (); i ++) {
27+ a = s .charAt (i );
28+ if (tmp .containsKey (a )) {
29+ index = tmp .get (a );
30+ // >= 非 >
31+ if (index >= start ) {
32+ start = tmp .get (a ) + 1 ;
33+ }
34+ }
35+ maxLength = Math .max (maxLength , i - start + 1 );
36+ tmp .put (a , i );
37+ }
38+ return maxLength ;
39+ }
40+
41+ public static void main (String [] args ) {
42+ Solution ss = new Solution ();
43+ System .out .println (ss .lengthOfLongestSubstring ("abcabcbb" ));
44+ System .out .println (ss .lengthOfLongestSubstring ("bbbbb" ));
45+ System .out .println (ss .lengthOfLongestSubstring ("pwwkew" ));
46+ System .out .println (ss .lengthOfLongestSubstring ("abba" ));
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments