problem0470

package
v0.0.0-...-d3fc627 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 1 Imported by: 0

README

470. Implement Rand10() Using Rand7()

题目

Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10which generates a uniform random integer in the range 1 to 10.

Do NOT use system's Math.random().

Example 1:

Input: 1
Output: [7]

Example 2:

Input: 2
Output: [8,4]

Example 3:

Input: 3
Output: [8,1,10]

Note:

  1. rand7 is predefined.
  2. Each testcase has one argument:n, the number of times that rand10 is called.

Follow up:

  1. What is the expected valuefor the number of calls torand7()function?
  2. Could you minimize the number of calls to rand7()?

解题思路

见程序注释

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL