假设给定链表为: ,若调用 searchValue(head, 5) ,函数返回值为( )。
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
正确答案:A
int searchValue(ListNode* head, int target) {
while (head != nullptr) {
if (head->val == target) {
return 1;
}
head = head->next;
}
return 0;
}
正确答案:A
想系统刷完 GESP C++ 1~8 级真题,并查看每道题的逐题精讲?
进入 GESPPASS 开始练习