-
Notifications
You must be signed in to change notification settings - Fork 0
1. Two Sum #13
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
base: main
Are you sure you want to change the base?
1. Two Sum #13
Conversation
There was a problem hiding this 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i + 1
から始めているので、i != jの条件は必要なさそうです。
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict()より{}を好む人もいるみたいですね
https://discord.com/channels/1084280443945353267/1198621745565937764/1244521323108241408
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
情報有難うございます!
個人的に{}
だとset
と紛らわしいので、dict()
を使ってます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有難うございます。勉強になります。
パフォーマンスにも影響するんですね。
nodchipさん、Exzrgsさん、nittocoさん、liquo-riceさん、レビューを有難うございました。 |
https://leetcode.com/problems/two-sum/description/