Skip to content

1. Two Sum#13

Open
TORUS0818 wants to merge 2 commits intomainfrom
1
Open

1. Two Sum#13
TORUS0818 wants to merge 2 commits intomainfrom
1

Conversation

@TORUS0818
Copy link
Copy Markdown
Owner

Copy link
Copy Markdown

@nodchip nodchip left a comment

Choose a reason for hiding this comment

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

よいと思います。

def twoSum(self, nums: List[int], target: int) -> List[int]:
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if i != j and nums[i] + nums[j] == target:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

i + 1から始めているので、i != jの条件は必要なさそうです。

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.

ほんとですね。有難うございます!

```python
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
num_to_index = dict()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

情報有難うございます!
個人的に{}だとsetと紛らわしいので、dict()を使ってます。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

有難うございます。勉強になります。
パフォーマンスにも影響するんですね。

@TORUS0818
Copy link
Copy Markdown
Owner Author

nodchipさん、Exzrgsさん、nittocoさん、liquo-riceさん、レビューを有難うございました。

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.

5 participants