Skip to content

1. Two Sum #11

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

1. Two Sum #11

wants to merge 1 commit into from

Conversation

rinost081
Copy link
Owner

No description provided.

```python
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
Copy link

Choose a reason for hiding this comment

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

seen という変数名ですと、 key と value にどのような値が含まれているのか分かりにくいと感じました。 num_to_index 等、 (keyが表すもの)_to_(valueが表すもの) といった命名はいかがでしょうか?

def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for i in range(len(nums)):
needed_value = target - nums[i]

Choose a reason for hiding this comment

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

nums を使っているので、needed_num もありかなと感じました。

- https://github.com/fhiyo/leetcode/pull/14/files?short_path=050f7e8#diff-050f7e8a6e8dcab5ada34b1061c96b59923387f92e6582826703e46c59d73557

- enumerateを使うやり方を紹介している人がいたが、本質的には変わらないなと思ったため実装は割愛する。
- 引き算をして何かをするというのは発送として持っていたが実装に活かせなかった。
Copy link

Choose a reason for hiding this comment

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

私がいいたいことはこれくらいです。

https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.w704ahvong3m

「あなたは部屋に入りました。数字の一つ書かれた紙を1000枚あります。その中から和が5000になる2枚を見つけてください。」というときに、100万回足し算しますかねえ。
https://discord.com/channels/1084280443945353267/1183683738635346001/1187304667126976532

どんどん先に進みましょう。

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.

4 participants