Skip to content

63. Unique Paths 2#34

Open
dxxsxsxkx wants to merge 1 commit into62_unique_pathsfrom
63_unique_paths_2
Open

63. Unique Paths 2#34
dxxsxsxkx wants to merge 1 commit into62_unique_pathsfrom
63_unique_paths_2

Conversation

@dxxsxsxkx
Copy link
Copy Markdown
Owner

for (int r = 0; r < num_row; r++) {
for (int c = 0; c < num_col; c++) {
if (obstacleGrid[r][c] == kObstacle) {
unique_paths[r][c] = 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.

この行は抜いて単にcontinueだけでも動きますかね?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

動きますね。自分は入れておいた方がわかりやすいかなと思って入れました。

例外処理。そもそもベクトルが blank の場合への対処と、ある行すべてに障害物があった場合に打ち切り処理を入れる方法。

- [参照](https://github.com/irohafternoon/LeetCode/pull/37/files)。
- 後者のケースってあんまり思いつかない。この処理を入れることによる計算の効率化の幅と、可読性の低下幅と、どっちが大きいだろう?都度判定を入れることになるので計算の効率化もそこまでされないのではと思う。
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

「打ち切り処理を入れるか」といったことは結局は、そのプログラムがどのようなものを扱うかの分布との兼ね合いです。

たとえば、ライブラリーのソート関数は、意外とすでにソート済みが入力に来ることが多い、と判断されて、すでにソート済みの場合は何もしない処理が入っていたりすることがあります。しかし、これは分布を試して確認しないことにはなんとも言えない話です。

なので、とりあえず、シンプルに作って、必要性との兼ね合いで後から入れることが割と好まれるのですね。

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.

3 participants