假设给定链表为:1→3→5→7→1 \to 3 \to 5 \to 7 \to1→3→5→7→ nullptr,若调用 searchValue(head, 5),函数返回值为( )。
nullptr
searchValue(head, 5)
int searchValue(ListNode* head, int target) { while (head != nullptr) { if (head->val == target) { return 1; } head = head->next; } return 0; }
返回 1
返回 0
死循环,无法返回
返回 -1