forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodingBat.java
More file actions
38 lines (35 loc) · 831 Bytes
/
CodingBat.java
File metadata and controls
38 lines (35 loc) · 831 Bytes
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
/**
* CodingBat examples from Chapter 8.
*/
public class CodingBat {
/**
* See https://codingbat.com/prob/p118230.
*/
public String noX(String str) {
if (str.length() == 0) {
return "";
}
char first = str.charAt(0);
String rest = str.substring(1);
String recurse = noX(rest);
if (first == 'x') {
return recurse;
} else {
return first + recurse;
}
}
/**
* See https://codingbat.com/prob/p135988.
*/
public int array11(int[] nums, int index) {
if (index >= nums.length) {
return 0;
}
int recurse = array11(nums, index + 1);
if (nums[index] == 11) {
return recurse + 1;
} else {
return recurse;
}
}
}