Today I learned
2022/01/19
회고록
항해 99, 알고리즘 1주차
교재 : 파이썬 알고리즘 인터뷰
10장 해시테이블
Given a string s, find the length of the longest substring without repeating characters.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
Constraints:
0 <= s.length <= 5 * 10^4
s consists of English letters, digits, symbols and spaces.
https://leetcode.com/problems/longest-substring-without-repeating-characters/
def solution(strs):
result = {}
for i in range(len(strs)):
result[1] = strs[i]
for j in range(i+1,len(strs)):
temp= strs[i:j]
if strs[j] not in temp:
if j-i+1 not in result:
result[j-i+1] = strs[i:j+1]
else:
break
ansKey=max(result.keys())
ret=result[ansKey]
return ansKey
if __name__ == '__main__':
strs = 'abcabcbb'
result = solution(strs)
print('result : ' + str(result))
해시 테이블 훈련