-
Notifications
You must be signed in to change notification settings - Fork 0
31. Next Permutation #63
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?
Conversation
| int first_increasing_order_index = nums.size() - 1; | ||
| while (first_increasing_order_index > 0) { | ||
| if (nums[first_increasing_order_index - 1] < nums[first_increasing_order_index]) { | ||
| break; | ||
| } | ||
| first_increasing_order_index--; | ||
| } |
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.
これを見て、first_increasing_order_index の初期化がここで終了したという理解は構造からは得られないと思うんですよね。たとえば、下はどうでしょうか。
int first_increasing_order_index = 0;
for (int i = num.size() - 1; i > 0; --i) {
if (...) {
first_increasing_order_index = i;
break;
}
}これは、0 がデフォルトで後ろから条件を満たすものを探して初期化したと読めますね。
const int first_increasing_order_index = get_first_increasing_order(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.
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.
@oda なるほどです。メタ認知力を鍛えたいと思ってそう言ったタイトルの本を読んでみたのですが、おすすめの本などあったりしますでしょうか?
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.
よく分かりません。
いや、まあ、でも一般的に国語力といわれるものが大事ですかねえ。
| next_permutation関数を使うのは、求めらていないだろう | ||
|
|
||
| ## ステップ3 | ||
| **3回書き直しやりましょう、といっているのは、不自然なところや負荷の高いところは覚えられないからです。** |
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.
なんとなく解くことが目的化しているというか、きれいなコードを GitHub に上げることが目的になっている感触を微かに持っています。(オンラインなのではっきりとは分かりません。)
この部分は、私がここで練習して欲しいことの2,3割です。
私が訓練したいのは、反応をするようになるとか感情を持てるようになるなどの内心です。
参加マニュアルを一回読み直してみてください。
http://docs.google.com/document/d/1bjbOSs-Ac0G_cjVzJ2Qd8URoU_0BNirZ8utS3CUAeLE
ただ、好きなようにやればいいとは思います。
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
一度マニュアルを読み直します。
31.NextPermutation/memo.md
Outdated
| pivot以降を逆順に並び変える箇所について | ||
| 元々pivot以降は降順に並んでいるので、reverseを使い結果として昇順に並び替えているが | ||
| sortを使った方がわかりやすいような気がする | ||
| o(n)からO(n log n)になるが、昇順に並び替えているというのは伝わりそう |
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.
小文字の o は意味が変わるので注意です。
|
|
||
| private: | ||
| // 右側が降順になっている範囲の直前のインデックスを探す | ||
| int FindDecreasingIndex(const vector<int>& 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.
nextPermutationとこちらの関数名のネーミングルールが揃っていないことに違和感があります。
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.
@usatie
レビューありがとうございます。
この会では可能な限りGoogleのスタイルガイドに合わせてコードを書いております。これはこの会以外ではC++を使うことがないためです。
全体で統一できればなのですが、LeetCodeで用意されている部分は仕方ないかなと思っております。
https://google.github.io/styleguide/cppguide.html#Function_Names
問題へのリンク
https://leetcode.com/problems/next-permutation/description/
問題文(プレミアムの場合)
備考
次に解く問題の予告
String to Integer (atoi)
フォルダ構成
LeetCodeの問題ごとにフォルダを作成します。
フォルダ内は、step1.cpp、step2.cpp、step3.cpp、lower_bound.cppとmemo.mdとなります。
memo.md内に各ステップで感じたことを追記します。