Skip to content

Missing Test Case - 470. Implement Rand10() Using Rand7() #30626

@wlj221

Description

@wlj221

LeetCode 用户名

吴立杰

问题号码、标题和链接

https://leetcode.cn/problems/implement-rand10-using-rand7/?envType=problem-list-v2&envId=rejection-sampling

Bug Category

问题限制

描述

No

你使用的语言

C

你提交或者运行的代码

#include <stdlib.h>

// 模拟 rand7() 函数(题目已提供)

int rand10() {
    int num;
    do {
        num = (rand7() - 1) * 7 + rand7(); // 生成 [1,49]
    } while (num > 40);                     // 拒绝 41~49
    return (num - 1) % 10 + 1;              // 映射到 [1,10]
}

期望行为

3ms

屏幕截图

No response

额外的上下文

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions