319. Check if Two Linked Lists are Identical

EasyLinked ListLinked ListTwo PointerComparison

Given two linked lists, return true if they are identical (same length and same values at each position), false otherwise.

Input: Heads of two singly linked lists.

Output: Boolean true if identical, false otherwise.

Examples

Example 1
Input: [1,2,3], [1,2,3]
Output: true
Explanation: All 3 nodes match. Return true.
Example 2
Input: [1,2,3], [1,2,4]
Output: false
Explanation: 3rd node: 3≠4. Return false.
Example 3
Input: [1,2],   [1,2,3]
Output: false
Explanation: Different lengths. Return false.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →