You are given the heads of two singly linked lists that may intersect. Your task is to return the value of the node where the two linked lists intersect. If the linked lists do not intersect, return -1.
Input: list1 = [4,1,8,4,5], list2 = [5,6,1,8,4,5] Output: 8 Explanation: Both linked lists intersect at the node with value 8.
Input: list1 = [1,9,1,2,4], list2 = [3,2,4] Output: 2 Explanation: The two linked lists intersect at the node with value 2.
Input: list1 = [2,6,4], list2 = [1,5] Output: -1 Explanation: The two linked lists do not intersect.
Sign in to write, run, and submit your solution against the full test suite.