https://leetcode.com/problems/longest-substring-without-repeating-characters/
Longest Substring Without Repeating Characters - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
Go 언어에서는 유니코드(UTF-8)를 표현할 때 rune 을 사용하는데
자꾸 string 화 시키려는 버릇이 있다
익숙하지가 않아서..
rune 좀 봐야될듯..
package main
func main() {
// s := "abcabcbb"
s := "pwwkew"
// s := "abcdefgasd"
lengthOfLongestSubstring(s)
}
// 제출 코드
func lengthOfLongestSubstring(s string) int {
var result int
slice := []string{}
if len(s) == 0 {
return result
} else {
for _, v := range s {
for j, vv := range slice {
if vv == string(v) {
slice = slice[j+1:]
break
}
}
slice = append(slice, string(v))
if len(slice) > result {
result = len(slice)
}
}
}
return result
}
'Algorithm > Go' 카테고리의 다른 글
[LeetCode] Maximum Subarray (0) | 2022.01.10 |
---|---|
[LeetCode] Longest Common Prefix (0) | 2022.01.09 |
[LeetCode] Minimum Index Sum of Two Lists (0) | 2022.01.03 |
[LeetCode] Merge Two Sorted Lists (0) | 2021.12.26 |
[LeetCode] Contains Duplicate (0) | 2021.12.26 |