← 返回题库
初级

生成Merkle证明路径

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve(leaves, target):
    leaves = leaves.split(',') if isinstance(leaves, str) else leaves
    idx = leaves.index(target)
    proof = []
    if idx % 2 == 0 and idx + 1 < len(leaves):
        proof.append(leaves[idx + 1])
    elif idx > 0:
        proof.append(leaves[idx - 1])
    print(proof)

示例

输入
solve('a,b,c,d', 'b')
期望输出
['a']
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码