【Google面经】onsite 2020 Random Generator Google Onsite 开发岗

飞天猪 2020-5-8 832


Write a RandomGenerator class:

public class RandomGenerator {

public RandomGenerator(int n) {

}

public int generate() {

// todo

}

}

The contructor will be passed an integer n. generate is supposed to return a random number between 0 to n, but it is not supposed to return a number that it has already returned. If possiblities are exhauted, return -1.

Example:

var rg = new RandomGenerator(3);

rg.generate(); // 0

rg.generate(); // 2

rg.generate(); // 1

rg.generate(); // -1

最后于 2020-6-1 被maomoke编辑 ,原因:
最新回复 (0)
返回