Skip to content

1. Two sum#11

Open
kitano-kazuki wants to merge 1 commit intomainfrom
1-two-sum
Open

1. Two sum#11
kitano-kazuki wants to merge 1 commit intomainfrom
1-two-sum

Conversation

@kitano-kazuki
Copy link
Owner

Copy link

@arahi10 arahi10 left a comment

Choose a reason for hiding this comment

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

コードはばっちりだとおもいます!
細かいところに感想を書きました.

if remain in num_to_idx:
return [num_to_idx[remain], i]
num_to_idx[num] = i
raise ValueError("No solution found") No newline at end of file
Copy link

@arahi10 arahi10 Mar 1, 2026

Choose a reason for hiding this comment

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

エラーメッセージは小文字始まりのほうがよく見るなと思いました.
というのも,pythonでエラーを起こさせてみると,

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range

みたく, (エラーの名前) : (エラーメッセージ)
のフォーマットで出力されるので, 大文字始まりで別の文章として独立させなくて良いと思っています.
あとは,今回の"no solution found"のようにわかりやすければエラーメッセージは文章じゃなくてもよいので,その点からも大文字始まりにしなくて良いと思います.

Copy link

@arahi10 arahi10 Mar 1, 2026

Choose a reason for hiding this comment

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

一方で,エラーメッセージが独立文なら,

という感じで,大文字始まりももちろん受け入れられるという認識です.

Copy link
Owner Author

Choose a reason for hiding this comment

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

色々と調べていただきありがとうございます!!知らなかったです!

if remain in num_to_idx:
return [num_to_idx[remain], i]
num_to_idx[num] = i
raise ValueError("No solution found") No newline at end of file

Choose a reason for hiding this comment

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

戻り値の型ヒントがlist[int]なので、raiseでエラーを出させるのは良いと思いました。optionalだったらreturn Noneとかで返したい気持ちになりました。

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.

3 participants