Coding Quiz - Check for Value Existence
In this coding quiz, your task is to convert a given list data into a Singly Linked List and then write a function to verify if a specific value target exists within the linked list.
The function should accept two arguments: a list of integers data, and the target value target you are looking for.
After constructing the linked list, the function should return True if the target value is found within the list and False if it is not.
Write Code
class ListNode:
def __init__(self, value=0, next=None):
self.value = value
self.next = next
def append(self, value):
if self.next is None:
self.next = ListNode(value)
else:
self.next.append(value)
def solution(data, target):
# Write your code here
return
Constraints
-
The
datalist consists of integers. -
targetis a single integer.
Example Input/Output
-
Input:
data = [1, 2, 4, 5],target = 3 -
Output:
False
-
Input:
data = [7, 8, 9],target = 7 -
Output:
True
Want to learn more?
Join CodeFriends Plus membership or enroll in a course to start your journey.