Created
July 18, 2018 03:39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The rand7() API is already defined for you. | |
// int rand7(); | |
// @return a random integer in the range 1 to 7 | |
class Solution { | |
public: | |
int rand10() { | |
int num = 40; | |
while (num >= 40) | |
num = 7 * (rand7() - 1) + (rand7() - 1); | |
return num % 10 + 1; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment