Skip to content

46 permutations#51

Open
kitano-kazuki wants to merge 5 commits into
mainfrom
46-permutations
Open

46 permutations#51
kitano-kazuki wants to merge 5 commits into
mainfrom
46-permutations

Conversation

@kitano-kazuki
Copy link
Copy Markdown
Owner

Comment thread memo.md
all_permutations = []

permutation = []
used_indices = set()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

used_indices = [False] * len(nums)

とすると、ハッシュの計算や、バケットのインデックスの計算が省け、軽くなると思います。

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 memo.md
class Solution:
def permute(self, nums: list[int]) -> list[list[int]]:

def generate_permutations(candidates: list[int], permutations: list[list[int]]):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

引数に型ヒントつけるなら,返り値の型ヒントもつけてはいかがでしょうか(Pythonのプラクティスでは返り値にはいちいちヒントをつけないこともある,とかだったらスルーしてください)

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 memo.md

## Code2-1

* 「今注目している候補以外でできるpermutationに候補を加える」という動作がわかりやすくなるようにした
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコードはより読みやすかったです.

Comment thread memo.md
* 今回は, デバッグのしやすさと解法の幅の観点から, 一つ一つのpermutationごとにstackに入れるようにした
* 一つのpermutationごとに次に選ぶ候補を保存しておく

```python
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらも素直に読めました.

Comment thread memo.md
Comment on lines +172 to +174

generate_permutations()

Copy link
Copy Markdown

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants