Py3 C++位元計算bitset速解Leetcode難題3307 Find the K th Character in String Game II
[codes on Leetcode]https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii/solutions/6917196/bits-count-for-k-1-operations-1-line-rec-mdud/
[bit/ bit mask play list]https://www.youtube.com/watch?v=Hw1fnQA8Nk8&list=PLYRlUBnWnd5K8FlzJ6tOswqQcsk7R1Duh
class Solution: def kthCharacter(self, k: int, operations: List[int]) -> str: return chr(97+((k-1) & sum(operations[b]<<b for b in range((k-1).bit_length()))).bit_count()%26)
沒有留言:
張貼留言
HTML 編輯器