題目
Given a string, find the length of the longest substring without repeating characters.
Example 1:
Input: "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
題目解釋
要看他給的Input字(s
)串中,最長的不重複字串長度。
思考方式
讀了別人的解答,整理以下思維:
- 宣告一個陣列
all
,裡面存放一個個字元拆開的s。 - 宣告一個暫存最長字元區
ans
。 - 遍歷s,無一樣的字元就丟進
ans
裡,有則清空ans
將重複的第一字元丟進ans
裡。
心得
有想法卻不知道怎麼實踐,是因為對可以使用的發法不太熟悉QQ幸好有很多大神提供答案參考,程式這條路總是孤單中又帶點不孤單,踩著別人的腳印往前走也是學很多,加油吧!