Skip to content

62. Unique Paths#9

Open
philip82148 wants to merge 1 commit into
mainfrom
31.unique-paths
Open

62. Unique Paths#9
philip82148 wants to merge 1 commit into
mainfrom
31.unique-paths

Conversation

@philip82148
Copy link
Copy Markdown
Owner

注意

ファイルが複数ある場合、<番号>.cppの<番号>が最も大きいものが最新版です!
最新版のみレビューお願いします!(もちろん過去のものをレビューしていただいても構いませんmm)

問題

https://leetcode.com/problems/unique-paths/description/?envType=problem-list-v2&envId=xo2bgr0r

using namespace std;

// <時間>
// 10分
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

10分で書けているなら、この問題はいいでしょう。

CPython の comb のコードを読んでいる人もいました。

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.

ありがとうございます!
この方などですね
nittoco/leetcode#26

public:
int uniquePaths(int m, int n) {
vector<vector<int>> num_paths(m, vector<int>(n));
for (int i = 0; i < m; ++i) num_paths[i][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.

私はぶら下がりは避けますね。

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.

僕はこちらで行かせていただきます(チームの時はチームに従います)
https://google.github.io/styleguide/cppguide.html#Formatting_Looping_Branching

For historical reasons, we allow one exception to the above rules: the curly braces for the controlled statement or the line breaks inside the curly braces may be omitted if as a result the entire statement appears on either a single line (in which case there is a space between the closing parenthesis and the controlled statement) or on two lines (in which case there is a line break after the closing parenthesis and there are no braces).

// OK - braces are optional in this case.
if (x == kFoo) return new Foo();

Copy link
Copy Markdown
Owner Author

@philip82148 philip82148 Feb 7, 2025

Choose a reason for hiding this comment

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

ちなみに↑のHistorical reasonsってどういう意味か聞いてもよいですか?
昔はぶら下がりifがたくさん使われてて、それを修正するのが大変だから、ぐらいの意味ですか?
(そして現代だとワンライナーぶら下がりifを新しく作るのはあまり主流ではない、という)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

書いた人に聞かないと分かりません。どっかのメーリングリストでやりとりがおこなわれておりました。

ただ、昔、慣習的に使われていた、(から好ましくないが慣れて読める人も多いので許す)くらいの温度感でしょう。

現代的な言語、たとえば Rust や Go や Swift などは {} が必要です。いらないのは C C++ Java などですね。

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.

なるほどです。ありがとうございます!

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.

2 participants