Skip to content

438. Find All Anagrams in a String - #114

Open
kazuki-official wants to merge 1 commit into
mainfrom
438-find-all-anagrams-in-a-string
Open

438. Find All Anagrams in a String#114
kazuki-official wants to merge 1 commit into
mainfrom
438-find-all-anagrams-in-a-string

Conversation

@kazuki-official

Copy link
Copy Markdown
Owner

Comment thread memo.md
return {};
}
std::unordered_map<char, int> letter_to_count_in_p;
for (const char& c : p) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
hemispherium/LeetCode_Arai60#10 (comment)

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.

変数の型サイズが CPU のレジスタ幅以下の場合、値渡しにしたほうが効率的な場合があります。

完全に盲点でした。変数の型サイズも意識するようにします。、

Comment thread memo.md
}

int num_incorrects = 0;
for (const auto& [letter, count] : letter_to_count_in_p) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

こちらのコメントをご参照ください。
5ky7/arai60#22 (comment)

今回のケースでは、値で受けたほうが良いと思います。

Comment thread memo.md
#include <vector>
#include <string>

const int NUM_ALPHABETS(26);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

定数を定義する際、コンパイル時に値が決まるものについては、 const より constexpr を使ったほうが良いと思います。
https://cpprefjp.github.io/lang/cpp11/constexpr.html

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.

今回はconstexprが良さそうですね。ありがとうございます。

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