-
Notifications
You must be signed in to change notification settings - Fork 0
46. Permutations #54
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?
46. Permutations #54
Conversation
| 次にその数字をもう一度選ぼうとすると同じ順列が再度生成される | ||
|
|
||
| # step1が終わって疑問に思ったこと | ||
| ・問題の制約上サイズ6が上限だがこれが、10であっらい100とかならどの様に解くのか? |
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.
100! はもう158桁とかなので現実的には無理ですね。
| return; | ||
| } | ||
|
|
||
| for (int num : nums) { |
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.
ここで nums で回すと計算量が少し悪くなりますが、そもそも重いので状況次第ですね。
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.
@oda
レビューありがとうございます。
step2_3で重複のチェク確認用にvector usedを用いました。まだこちらの方がマシでしょうか。
ただ実装は大変だと感じました。
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 で notused を持てばいいです。
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.
あ、ここ nums で回しちゃうと、O(n! * n) の n が残っちゃうんですね。
ただ、変更しながらループで回すことはできないので、コピーすることになります。
それでも、最後の n はなくなります。
問題へのリンク
https://leetcode.com/problems/permutations/description/
問題文(プレミアムの場合)
備考
次に解く問題の予告
Subsets
フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step2_2.cpp、step2_3.cpp、step2_4.cpp、step3.cppとmemo.mdとなります。
memo.md内に各ステップで感じたことを追記します。