← 返回 meta 的题目列表Compare Two Linked Lists' Concatenated Strings
类型:online_judge
Given two singly linked lists head1 and head2. Each node has a string value node.val (possibly empty). Concatenate node strings from head to tail to form two strings S1 and S2.
Return whether S1 and S2 are exactly equal.
Requirements
You may not build the full concatenated strings explicitly before comparing (streaming/incremental comparison is required).
Target time complexity: O(total_chars).
Input format (for an online judge)
Line 1: integer n
Next n lines: node strings for the first list
Next line: integer m
Next m lines: node strings for the second list
Output
One line: true or false
Constraints
0 <= n, m <= 2*10^5
Sum of all characters across both lists ≤ 2*10^5
Example Input:
3
ab
c
2
a
bc
Output:
true
Example
Input
3
ab
c
2
a
bc
Output
true