#217. 递归查找数组中的特定数字
递归查找数组中的特定数字
Find Number 6 Recursively
Background
Congcong is currently learning about recursive algorithms. He encountered an interesting problem that requires determining if a specific number is present in an integer array.
Problem Description
Given an array of integers, compute recursively if the array contains the number . We'll use the convention of considering only the part of the array that begins at the given index. In this way, a recursive call can pass to move down the array. The initial call will pass in as .
Input Format
Input is given from standard input in the following format.
A single line containing several integers. The last integer represents the starting index , and all preceding integers form the array to be checked.
Output Format
Output is printed to standard output in the following format.
Output
trueif the array contains ; otherwise, outputfalse.
Sample
1 6 4 0
true
1 4 0
false
6 0
true
Sample Explanation
For the first sample 1 6 4 0:
The array is [1, 6, 4] and the starting index is .
Starting from index , the array element is , which is not .
A recursive call checks the array part [6, 4] starting from index .
is , so it returns true.
Constraints
Time limit for each test case is second, and memory limit is KiB.