#91. 比较数组首尾N个元素
比较数组首尾N个元素
Compare Array Ends
Background
Problem Description
Return true if the group of numbers at the start and end of the array are the same. For example, with an array , the ends are the same for and , and false for and . You may assume that is in the range inclusive.
Input Format
Input is given from standard input in the following format.
A single line containing a string representation of an integer array
nums(e.g.,[1 2 3]), followed by a space and an integer .
Output Format
Output is printed to standard output in the following format.
A boolean value:
trueorfalse.
Sample
[5 6 45 99 13 5 6] 1
false
[5 6 45 99 13 5 6] 2
true
[5 6 45 99 13 5 6] 3
false
Sample Explanation
For Sample 1, the array is [5, 6, 45, 99, 13, 5, 6] and . The first 1 number of the array is [5], and the last 1 number of the array is [6]. They are not the same, so false is returned.
For Sample 2, the array is [5, 6, 45, 99, 13, 5, 6] and . The first 2 numbers of the array are [5, 6], and the last 2 numbers of the array are [5, 6]. They are the same, so true is returned.
For Sample 3, the array is [5, 6, 45, 99, 13, 5, 6] and . The first 3 numbers of the array are [5, 6, 45], and the last 3 numbers of the array are [13, 5, 6]. They are not the same, so false is returned.
Constraints
Time limit: 1 second, Memory limit: 1024 KiB for each test case.