-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathRecursion_FirstIndexOfNumber.java
52 lines (33 loc) · 1.19 KB
/
Recursion_FirstIndexOfNumber.java
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
51
52
public class Recursion_FirstIndexOfNumber {
public static int indexBtao(int input[], int x, int startIndex){
int len = input.length;
if (startIndex==len-1){
return -1;
}
if (input[startIndex] == x){
return startIndex;
}
int jawaab = indexBtao(input, x, startIndex+1);
return jawaab;
}
public static int firstIndex(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.
*/
// int[] smallInput = new int[len-1];
// for(int i = 1; i<len-1; i++){
// smallInput[i-1] = input[i];
// }
// int ans = firstIndex(smallInput, x);
// if (input[0] == x){
// return 0;
// }else{
// return ans;
// }
int ans = indexBtao(input,x,0);
return ans;
}
}