力扣470. 用 Rand7() 实现 Rand10()

class Solution:
    def rand10(self) -> int:
        while True:
            row = rand7()
            col = rand7()
            idx = (row - 1) * 7 + col
            if idx <= 40:
                return 1 + (idx - 1) % 10

# 作者:LeetCode-Solution
# 链接:https://leetcode-cn.com/problems/implement-rand10-using-rand7/solution/yong-rand7-shi-xian-rand10-by-leetcode-s-qbmd/
# 来源:力扣(LeetCode)
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

力扣470. 用 Rand7() 实现 Rand10()

 官方题解答案

上一篇:470. 用 Rand7() 实现 Rand10() 采样


下一篇:LeetCode 470.用Rand7()实现Rand10()