Skip to content

17. Letter Combinations of a Phone Number - #112

Open
kazuki-official wants to merge 1 commit into
mainfrom
17-letter-combinations-of-a-phone-number
Open

17. Letter Combinations of a Phone Number#112
kazuki-official wants to merge 1 commit into
mainfrom
17-letter-combinations-of-a-phone-number

Conversation

@kazuki-official

Copy link
Copy Markdown
Owner

Comment thread memo.md
#include <vector>


const std::unordered_map<char, std::vector<char>> DIGIT_TO_LETTERS = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

コーディングスタイルによっては、定数の変数名を kDigitToLetters とする場合もあります。

参考までにスタイルガイドへのリンクを共有いたします。

https://google.github.io/styleguide/cppguide.html#Constant_Names

Variables declared constexpr or const, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case.

なお、このスタイルガイドは“唯一の正解”というわけではなく、数あるガイドラインの一つに過ぎません。チームによって重視される書き方や慣習も異なります。そのため、ご自身の中に基準を持ちつつも、最終的にはチームの一般的な書き方に合わせることをお勧めします。

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.

最初にkをつけるスタイルがあるのですね。勉強になります。

Comment thread memo.md
#include <vector>


const std::unordered_map<char, std::vector<char>> DIGIT_TO_LETTERS = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

static が付いていない場合、他の翻訳単位から extern することで、このインスタンスを参照することができます。他の翻訳単位から参照する必要がない場合は、翻訳単位内からのみ参照できるようにするため、 static を付けても良いかもしれません。

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.

今回はstaticをつけた方が良さそうですね。ありがとうございます。

Comment thread memo.md
public:
std::vector<std::string> letterCombinations(std::string digits) {
return LetterCombinations(digits, 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.

インデントの位置が合っていないようです。

Comment thread memo.md
std::vector<std::string> combinations;
std::vector<std::string> child_combinations = LetterCombinations(digits, i + 1);
for (char letter : DIGIT_TO_LETTERS.at(digits[i])) {
for (std::string child_combination : child_combinations) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

std::string のコピーは、ヒープの確保と解放が入るため重いです。 const std::string& で受けたほうが良いと思います。

Comment thread memo.md
Comment on lines +161 to +164


}

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants