#91. 比较数组首尾N个元素

    ID: 91 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatArray-2gesp3一维数组

比较数组首尾N个元素

Compare Array Ends

Background

Problem Description

Return true if the group of NN numbers at the start and end of the array are the same. For example, with an array {5,6,45,99,13,5,6}\{5, 6, 45, 99, 13, 5, 6\}, the ends are the same for N=0N=0 and N=2N=2, and false for N=1N=1 and N=3N=3. You may assume that NN is in the range 0extnums.length0 \dots ext{nums.length} 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 NN.

Output Format

Output is printed to standard output in the following format.

A boolean value: true or false.

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 N=1N=1. 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 N=2N=2. 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 N=3N=3. 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.