Closed MuhammadTausif closed 4 hours ago
class Solution:
def count(self, head, key):
current = head
ans = 0
while current is not None:
if current.data == key:
ans += 1
current = current.next
return ans
Occurence of an integer in a Linked List
Link
Difficulty: Easy
Given a singly linked list and a key, count the number of occurrences of the given key in the linked list.
Examples:
Explanation: 3 appears 0 times. Expected Time Complexity: O(n) Expected Auxiliary Space: O(1)
Constraints: