-
Notifications
You must be signed in to change notification settings - Fork 36
/
Searching in Array
50 lines (44 loc) · 1.13 KB
/
Searching in Array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class Runner {
static Scanner s = new Scanner(System.in);
public static void main(String[] args) {
int n = s.nextInt();
int input[] = new int[n];
for(int i = 0; i < n; i++) {
input[i] = s.nextInt();
}
int x = s.nextInt();
System.out.println(Solution.checkNumber(input, x));
}
}
public class Solution {
public static boolean checkNumber(int input[], int x) {
/* Your class should be named Solution
* Don't write main().
* Don't read input, it is passed as function argument.
* Return output and don't print it.
* Taking input and printing output is handled automatically.
*/
if(input.length==1){
if(input[0]==x){
return true;
}
else{
return false;
}
}
int smallerArray[]=new int[input.length-1];
for(int i=1;i<input.length;i++){
smallerArray[i-1]=input[i];
}
boolean val=checkNumber(smallerArray,x);
if(val==true){
return true;
}else{
if(input[0]==x){
return true;
}
}
return false;
}
}