542. 01 Matrix - #73
Open
naoto-iwase wants to merge 1 commit into
Open
Conversation
huyfififi
reviewed
Dec 20, 2025
|
|
||
| num_rows = len(mat) | ||
| num_cols = len(mat[0]) | ||
| INF = num_rows + num_cols |
There was a problem hiding this comment.
この変数はinfiniteではなくINFと名付けるのはやや誤解を招くので、max_distなどの方が意図が伝わりやすい気がします。
INFという変数名をみて個人的に気になったのは
- math.inf / float("inf")を使用しない理由は何だろう
- infiniteという名付けだけど、実際はこの変数の値を超える変数が作れるな、どこかに落とし穴はないだろうか
という点です。
また、固定の数字 (constant) という意味で大文字を使用されているものと予想しますが、関数への入力によって変化する数字なのでconstantではなく、この場合は小文字を使用するパターンの方をよく見るかなと思います。詳しくconstantの定義は調べていませんが...
Owner
Author
There was a problem hiding this comment.
ありがとうございます。
命名、大文字、どちらも同意です。
max_dist, max_distanceなどが良さそうですね。
huyfififi
reviewed
Dec 20, 2025
| ### 実装3 | ||
|
|
||
| - アルゴリズムの検討 | ||
| - 移動方向を制限してTwo-passでやる方法は定数倍で速そう。 |
There was a problem hiding this comment.
ただの感想ですが、この解法は万人が思いつき、腑に落ちて、どこかに問題が発生した時にロジックを修正できるものではないかなと思っています。(ちょっと魔法?っぽい?)
私がもし業務で似たような課題を与えられたら、大体現実的にとり得る入力サイズを確認して、実行時間に問題がなさそうならBFSを選択すると思います。愚直な方針の方が、長期的にメンテナンスしやすいかなと。(この辺の匙加減は私も調整中なので、感想まで)
nodchip
reviewed
Dec 22, 2025
| DIRECTIONS = [(1, 0), (-1, 0), (0, 1), (0, -1)] | ||
| result = [[UNVISITED] * num_cols for _ in range(num_rows)] | ||
|
|
||
| def is_to_visit(row, col): |
There was a problem hiding this comment.
自分なら is_visitable() と名付けると思いますが、趣味の範囲だと思います。英語句として自然かどうか自信ありません。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
542. 01 Matrix
Next: 973. K Closest Points to Origin