// The rand7() API is already defined for you.// int rand7();// @return a random integer in the range 1 to 7classSolution{public:intrand10(){intnum=40;while(num>=40)num=(rand7()-1)*7+rand7()-1;returnnum%10+1;}};
1 2 3 4 5 6 7 8 910111213141516
/** * The rand7() API is already defined in the parent class SolBase. * public int rand7(); * @return a random integer in the range 1 to 7 */classSolutionextendsSolBase{publicintrand10(){intnum=40;while(num>=40)num=(rand7()-1)*7+rand7()-1;returnnum%10+1;}}