Skip to content

Conversation

hroc135
Copy link
Owner

@hroc135 hroc135 commented Mar 22, 2025

if len(s) == 0 {
return 0
}
charToLastIndex := make(map[byte]int)

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

Copy link
Owner Author

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

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
- 自分のやりたいことをより少ない行数で実装していた
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね。上のコードを見て、形式的にも色々できそうですね。
たとえば、ループで次に行くときに right++ をしているので for に直りそうとか、実は、= right のところが同じとか。

Comment on lines +167 to +168
- UnicodeとUTF-8
- いつもわからなくなる

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 {
Copy link

@olsen-blue olsen-blue Mar 29, 2025

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 と書いた方が良いかもという気がしてきました...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants