题目描述
Given a linked list of n nodes and a key , the task is to check if the key is present in the linked list or not.
Example:
Input:
n = 4
1->2->3->4
Key = 3
Output:
True
Explanation:
3 is present in Linked List, so the function returns true.
Your Task:
Your task is to complete the given function searchKey(), which takes a head reference and key as Input and returns true or false boolean value by checking the key is present or not in the linked list.
Constraint:
1 <= n <= 10^{5}
1 <= key <= 10^{5}
Expected Time Complexity: O(n)
Expected Space Complexity: O(1)
输入格式
见题面
输出格式
见题面
样例输入
n = 4
1->2->3->4
Key = 3
样例输出
True