Implement Rand10() Using Rand7()

Problem Id: 470 Difficulty: Medium


Intuition

Solution


class Solution:
    def __init__(self):
        self.seed = 1
    def rand10(self):
        """
        :rtype: int
        """
        self.seed += rand7()
        if self.seed >= 10:
            self.seed = self.seed % 10
        return self.seed + 1