-
Notifications
You must be signed in to change notification settings - Fork 0
3. Longest Substring Without Repeating Characters #42
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?
3. Longest Substring Without Repeating Characters #42
Conversation
fhiyo
left a comment
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.
良いと思います!
| let mut head = 0; | ||
| let mut tail = 0; |
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.
rihib/leetcode#7 (comment) にも書いたんですが、head, tailがindexなの個人的には少し違和感あります。
(が、コメント見たうえでそうでもないよとかあれば教えて下さい)
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.
ありがとうございます
いわれてみれば確かに... left, rightのほうが自然ですね
なんでhead, tailになれてるかというと、sliding windowってもともとしゃくとり法って名前で知ったんですよね
そこでしゃくとり虫の頭と尻尾を移動する感覚で覚えちゃって、手癖になっていたようです
コメントありがとうござます
| // HashMapを使った解法 | ||
| pub fn length_of_longest_substring_1(s: String) -> i32 { | ||
| let mut head = 0; | ||
| let mut tail = 0; |
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.
こちら参考にしてもらえると🙏
僕もhead, tailを使ってたんですが、Sliding Windowアルゴリズム(またはTwo Pointers)として捉えると、left, rightを使う方が一般的っぽいですね、、
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.
すいません、fhiyoさんと同時に同じ箇所を指摘してしまいましたw
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.
|
コメントした箇所以外は良いと思いました! |
thonda28
left a comment
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.
ans という変数名が汎用的すぎて少し引っかかりましたが、それ以外はよさそうに思いました。
半開区間に設定するのも1つの手だと思いましたが、以下のコメントを見るに Rust には不向きみたいですね。
fhiyo/leetcode#49 (comment)
|
はい、Rustではindex accessは |
| head += 1 | ||
| } | ||
| unique_chars.insert(chars[tail]); | ||
| ans = ans.max(tail - head + 1); |
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.
https://doc.rust-lang.org/core/primitive.i32.html#method.max
ほー、こんなのがあるんですね。
問題: https://leetcode.com/problems/longest-substring-without-repeating-characters/description/
次に解く問題: https://leetcode.com/problems/minimum-size-subarray-sum/description/
ファイルの構成
problems/src/<解いた問題名>/以下にstep1~step3のファイルを保存しています