码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Implement Rand10() Using Rand7() 使用Rand7()来实现Rand10()

时间:2018-09-30 00:24:33      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:led   efi   using   ref   output   cti   实现   def   rate   

  

Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which 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 value for the number of calls to rand7() function?
  2. Could you minimize the number of calls to rand7()?

 

s

 

[LeetCode] Implement Rand10() Using Rand7() 使用Rand7()来实现Rand10()

标签:led   efi   using   ref   output   cti   实现   def   rate   

原文地址:https://www.cnblogs.com/grandyang/p/9727206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!