Skip to content

779. K-th Symbol in Grammar#34

Open
n6o wants to merge 1 commit into
mainfrom
k-th-symbol-in-grammar
Open

779. K-th Symbol in Grammar#34
n6o wants to merge 1 commit into
mainfrom
k-th-symbol-in-grammar

Conversation

@n6o
Copy link
Copy Markdown
Owner

@n6o n6o commented Apr 27, 2026

今回の問題

K-th Symbol in Grammar - LeetCode

使用言語

Python

if n == 2:
return 0 if k == 1 else 1

mid = pow(2, n - 2)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

整数の 2 の p 乗を求める際は、 1 << p を使うこともあります。一般に pow() 関数より 1 << p のほうが速いため、原則 1 << p を使ったほうが良いかもしれません。チーム内に不慣れな方がいらっしゃる場合は、避けたほうが良いかもしれません。

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.

ありがとうございます。

ビットシフトも使うことを思いつきにくかったので、これからは整数の 2 の p 乗を求めるときに最初の案として使うようにします。

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