力扣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)
# 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
官方题解答案
标签:idx,题解,Rand10,while,rand7,力扣,470,col,row 来源: https://blog.csdn.net/qq_40665593/article/details/120121166