Open
Conversation
5ky7
reviewed
Mar 4, 2026
5ky7
left a comment
There was a problem hiding this comment.
全体的に読みやすかったです!
動的計画でやる場合「一方通行の更新は1次元配列のみでできる」ということを見落としていたので良い気づきになりました.
Comment on lines
+19
to
+20
| final rows = obstacleGrid.length; | ||
| final cols = obstacleGrid[0].length; |
There was a problem hiding this comment.
今回のコードの長さであれば問題ないと思いますが,個人的には中身を明確に表すnum_rows, num_colsの方が好みです.
mamo3gr
reviewed
Mar 5, 2026
Comment on lines
+68
to
+69
| for (var row = 0; row < rows; row++) { | ||
| for (var col = 0; col < cols; col++) { |
There was a problem hiding this comment.
行数 rows と、インデックスである row が字面の上で似ているので、インデックスを r にするとか、行数を num_rows にするなどして区別しやすいようにすると良いと思いました。
mamo3gr
reviewed
Mar 5, 2026
|
|
||
| for (var row = 0; row < rows; row++) { | ||
| for (var col = 0; col < cols; col++) { | ||
| if (obstacleGrid[row][col] == obstacle || (row == 0 && col == 0)) { |
There was a problem hiding this comment.
結果としては同じ (continue) になるものの、状況が違うので、if文を分けたほうが分かりやすいと感じました。
mamo3gr
reviewed
Mar 5, 2026
| uniquePathsCount[0][0] = 1; | ||
|
|
||
| int uniquePaths(int row, int col) { | ||
| if (row < 0 || row >= rows || col < 0 || col >= cols) { |
There was a problem hiding this comment.
Dartはchained comparisonを採用していなさそうですね(cf).
not (0 <= row && row < rows)のように「『正しいケース』ではない」という自然言語の説明に近いコードの方が意図がわかりやすいという点は同感です.
|
相変わらず読みやすかったです! |
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.
解いた問題:https://leetcode.com/problems/unique-paths-ii/description/
次に解く問題:https://leetcode.com/problems/house-robber/description/