#9. 判断两数组首尾元素是否相同
判断两数组首尾元素是否相同
Same First Last Element
Background
(No specific background)
Problem Description
Given two integer arrays, and , return true if they have the same first element or they have the same last element. Both arrays will be length or more.
Input Format
Input is given from standard input in the following format.
First line: Space-separated integers representing elements of array . Second line: Space-separated integers representing elements of array .
Output Format
Output to standard output in the following format.
Output
trueif the condition is met; otherwise, outputfalse.
Sample
1 2 3
7 3
true
1 2 3
7 3 2
false
1 2 3
1 3
true
Sample Explanation
Sample 1: The first element of array is , and the last element is . The first element of array is , and the last element is . Since their last elements are the same (both ), it returns true.
Sample 2: The first element of array is , and the last element is . The first element of array is , and the last element is . The first elements are different, and the last elements are also different, so it returns false.
Sample 3: The first element of array is , and the last element is . The first element of array is , and the last element is . Since their first elements are the same (both ), it returns true.
Constraints
For each test case: Time limit second, Memory limit KiB. Both arrays and will be length or more.