【Leetcode刷题】:Python:470. 用 Rand7() 实现 Rand10()
作者:互联网
题目
题解:
代码:
# The rand7() API is already defined for you.
# def rand7():
# @return a random integer in the range 1 to 7
class Solution:
def rand10(self):
"""
:rtype: int
"""
while True:
nums = (rand7()-1)*7 + rand7()
if nums <= 40:
return nums % 10 + 1
标签:nums,Python,Rand10,rand10,rand7,470,Rand7 来源: https://blog.csdn.net/weixin_37251044/article/details/121702154