第23655题 单选
给定指定单链表和C++的searchValue函数,调用searchValue(head, 5)的返回值为多少?

给定链表结构为:1 → 3 → 5 → 7 → nullptr searchValue函数实现如下:

int searchValue(ListNode* head, int target) {
    while (head != nullptr) {
        if (head->val == target) {
            return 1;
        }
        head = head->next;
    }
    return 0;
}
A

返回1

B

返回0

C

死循环,无法返回

D

返回-1

提交0次 正确率0.00%
答案解析