48問目 3. Longest Substring Without Repeating Characters#48
Merged
shining-ai merged 3 commits intomainfrom Jun 29, 2024
Merged
Conversation
nodchip
reviewed
Apr 12, 2024
| def lengthOfLongestSubstring(self, s: str) -> int: | ||
| if not s: | ||
| return 0 | ||
| seen_index = {} |
There was a problem hiding this comment.
dict のキーが文字であるという点が、変数名から理解しずらく感じました。 char_to_last_index はいかがでしょうか?
Owner
Author
There was a problem hiding this comment.
変数名がsetぽくなっていますね。
分かりやすい変数名のご提案ありがとうございます。
hayashi-ay
reviewed
Apr 12, 2024
| def lengthOfLongestSubstring(self, s: str) -> int: | ||
| max_length = 0 | ||
| for i, base_c in enumerate(s): | ||
| seen = set(base_c) |
There was a problem hiding this comment.
自分ならここの処理も後続のfor分で合わせてやるかなと思いました。
length = 0
for c in s[i:]:
Comment on lines
+24
to
+25
| if not s: | ||
| return 0 |
Owner
Author
There was a problem hiding this comment.
空文字の時、rightが存在しなくてエラーになってしまうんですよね。
right = -1
の初期化だと意図がつかめないかと思い、not sをチェックしました。
There was a problem hiding this comment.
なるほど、ちゃんと読めてなかったです。for文で定義した変数をその外で使うのが良くないと思うんですよね。Pythonの言語仕様的には問題ないですが。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
問題
https://leetcode.com/problems/longest-substring-without-repeating-characters/