Skip to content

Create 01_two_sum.md - #4

Open
Kitaken0107 wants to merge 1 commit into
mainfrom
Kitaken0107-patch-5
Open

Create 01_two_sum.md#4
Kitaken0107 wants to merge 1 commit into
mainfrom
Kitaken0107-patch-5

Conversation

@Kitaken0107

Copy link
Copy Markdown
Owner

@hayashi-ay hayashi-ay left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2ndはforループを1回回すだけでも良いですね。

Comment thread 01_two_sum.md
for j in range(i+1,len(nums),1):
if target == nums[i] + nums[j]:
return [i,j]
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

このbreak文不要じゃないですか?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

返り値確定したら、その後の処理不要ですもんね。
理解しました。
コメントありがとうございます。

Comment thread 01_two_sum.md
for i in range(len(nums)):
table[nums[i]] = i
for i in range(len(nums)):
sub = target - nums[i]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

subの変数名がよく分からなかったです。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

引き算の単語の最初の3文字を書いてみたのですが、
たしかに連想しづらいのとそもそも引き算の単語にする必要ないですね。
ベストものぱっと思いつかないですが、ほかの方の命名確認してみます。

Comment thread 01_two_sum.md
for i in range(len(nums)):
sub = target - nums[i]
if sub in table and table[sub] != i:
return [i,table[sub]]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return [i,table[sub]] -> return [i, table[sub]]

Comment thread 01_two_sum.md
for i in range(len(nums)):
for j in range(i+1,len(nums),1):
if target == nums[i] + nums[j]:
return [i,j]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

return [i,j] -> return [i, j]

Comment thread 01_two_sum.md
def twoSum(self, nums: List[int], target: int) -> List[int]:

for i in range(len(nums)):
for j in range(i+1,len(nums),1):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

for j in range(i+1,len(nums),1): -> for j in range(i+1, len(nums), 1):

@rihib rihib mentioned this pull request Aug 6, 2024
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