第20806题 单选
给定链表与searchValue函数,调用searchValue(head, 5)的返回值是

假设给定链表为: 1→3→5→7→nullptr

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%
答案解析