← 返回 meta 的题目列表Check if Two Linked Lists Represent the Same Character Sequence
类型:online_judge
meta
Given two linked lists representing sequences of characters, determine if they can form the same word.
Example:
Input: list1 = ['a', 'b', 'c'], list2 = ['c', 'b', 'a'], Output: False
Input: list1 = ['a', 'b', 'c'], list2 = ['a', 'b', 'c'], Output: True
Input: list1 = ['a', 'a'], list2 = ['a', 'a'], Output: True
Requirements:
The order of characters in the linked lists must not change.
Time complexity: O(n + m), where n and m are the lengths of the two lists respectively.
Input Description:
Linked lists list1 and list2 representing the sequences of characters to compare.
Output Description:
Return True if the character sequences represented by the two linked lists are the same, otherwise return False.
Example
Input
a b c\nc b a