-
Notifications
You must be signed in to change notification settings - Fork 0
3. Longest Substring Without Repeating Characters #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
if len(s) == 0 { | ||
return 0 | ||
} | ||
charToLastIndex := make(map[byte]int) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
確認済みかもですが、ASCIIの特性を活かした解法もあるようです🙇♂️
philip82148/leetcode-swejp#3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
共有ありがとうございます。書いてみました。
const AsciiCodepointNum = 128
func lengthOfLongestSubstring(s string) int {
var charLastIndex [AsciiCodepointNum]int
for i := range charLastIndex {
charLastIndex[i] = -1
}
result := 0
substringStartIndex := 0
for i := 0; i < len(s); i++ {
if charLastIndex[uint8(s[i])] >= substringStartIndex {
substringStartIndex = charLastIndex[uint8(s[i])] + 1
}
charLastIndex[uint8(s[i])] = i
result = max(result, i-substringStartIndex+1)
}
return result
}
} | ||
``` | ||
|
||
### CS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この辺りの学習いいですね。
#### 2a | ||
- step1の修正 | ||
- https://github.com/olsen-blue/Arai60/pull/49/files#diff-eaf04e4839867b1c256a01b37e3fd908cd889582123148e5910d72e4e4fcb421R53 | ||
- 自分のやりたいことをより少ない行数で実装していた |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
そうですね。上のコードを見て、形式的にも色々できそうですね。
たとえば、ループで次に行くときに right++ をしているので for に直りそうとか、実は、= right のところが同じとか。
- UnicodeとUTF-8 | ||
- いつもわからなくなる |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
永遠によくわかっていなかったです。参考になります。
charToLastIndex := make(map[rune]int) | ||
result := 0 | ||
left := 0 | ||
for right, c := range s { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
私は、グリッドのインデックスにr, cを使いがちなので、一瞬 c の意味を捉えられませんでした。charと書いても良いのかもしれないですね。
同時に私も r, c ではなく row, col と書いた方が良いかもという気がしてきました...
https://leetcode.com/problems/longest-substring-without-repeating-characters/description/