Skip to content

78. Subsets#52

Open
kitano-kazuki wants to merge 1 commit into
mainfrom
78-subsets
Open

78. Subsets#52
kitano-kazuki wants to merge 1 commit into
mainfrom
78-subsets

Conversation

@kitano-kazuki
Copy link
Copy Markdown
Owner

Comment thread memo.md
def subsets(self, nums: list[int]) -> list[list[int]]:

all_subsets = [[]]
for i in range(len(nums)):
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 は使っていないので、直接 num を取り出すのが良いと思いました。

この解法を簡潔にすると以下のようにも書けそうです。

class Solution:
    def subsets(self, nums: list[int]) -> list[list[int]]:
        all_subsets = [[]]
        for num in nums:
            all_subsets += [subset + [num] for subset in all_subsets]
        return all_subsets

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.

そうですね。ありがとうございます

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.

2 participants