Skip to content

Conversation

@nittoco
Copy link
Owner

@nittoco nittoco commented Jul 20, 2024

https://leetcode.com/problems/k-th-symbol-in-grammar/description/ We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110. Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.

https://leetcode.com/problems/k-th-symbol-in-grammar/description/
We build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.

For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.
Given two integer n and k, return the kth (1-indexed) symbol in the nth row of a table of n rows.
@goto-untrapped
Copy link

良さそうに思います!

@SuperHotDogCat
Copy link

良いと思います

Copy link

@hayashi-ay hayashi-ay left a comment

Choose a reason for hiding this comment

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

良いと思います。

https://stackoverflow.com/questions/109023/count-the-number-of-set-bits-in-a-32-bit-integer

- x86というプロセッサなら命令がそのままあるらしい
- それ使わないやつが非常に面白い。(偶数bit + 奇数bit)によって先頭から2桁ずつbitcountして結果を2桁ずつに収める、先頭から4桁ずつbitcountして結果を4桁ずつに収める、を順に行う(説明が下手)
Copy link

Choose a reason for hiding this comment

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

https://www.oreilly.co.jp//books/9784873112886/mobile.html
「Binary Hacks ─ ハッカー秘伝のテクニック100選」薦めておきます。

Copy link

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

そうでした。すみません、混ざってました。

Copy link
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.

8 participants