Skip to content

63. Unique Paths II#47

Open
colorbox wants to merge 1 commit intomainfrom
63
Open

63. Unique Paths II#47
colorbox wants to merge 1 commit intomainfrom
63

Conversation

@colorbox
Copy link
Copy Markdown
Owner

public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
if (obstacleGrid[0][0] == 1) { return 0; }
if (obstacleGrid.back().back() == 1) { return 0; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

これはなくても動きそうですね。高速化と可読性の兼ね合いですかね。

Copy link
Copy Markdown

@5ky7 5ky7 left a comment

Choose a reason for hiding this comment

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

読みやすかったです.

return 0;
}

step_count[0][0]=1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: 代入演算子の前後にはスペースを置くスタイルが一般的に思います.cf

Comment on lines +10 to +11
for (int y = 0; y < obstacleGrid.size(); ++y) {
for (int x = 0; x < obstacleGrid[0].size(); ++x) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ただの好みですが,x,yよりrow, colあるいはi, jの方が自然な順番になって好きです.

Comment on lines +11 to +13
if (i == 0 && j == 0) {
continue;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

後半の処理と内容が重複しているので、消しても動きそうです。

Suggested change
if (i == 0 && j == 0) {
continue;
}

Comment on lines +10 to +11
for (int y = 0; y < obstacleGrid.size(); ++y) {
for (int x = 0; x < obstacleGrid[0].size(); ++x) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

obstacleGrid.size()obstacleGrid[0].size() を一度変数に置いたほうが、考えている座標系が伝わりやすいと思いました。個人的には row, col が分かりやすいです(y, x はそれぞれの次元との対応が必ずしも決まっているとは限らないので)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants