|
@@ -1,5 +1,8 @@
|
1
|
1
|
package io.zipcoder;
|
2
|
2
|
|
|
3
|
+import java.util.Arrays;
|
|
4
|
+import java.util.List;
|
|
5
|
+
|
3
|
6
|
public class StringsAndThings {
|
4
|
7
|
|
5
|
8
|
/**
|
|
@@ -11,7 +14,14 @@ public class StringsAndThings {
|
11
|
14
|
* countYZ("day fyyyz"); // Should return 2
|
12
|
15
|
*/
|
13
|
16
|
public Integer countYZ(String input){
|
14
|
|
- return null;
|
|
17
|
+ int count = 0;
|
|
18
|
+ for (String e : input.split(" ")) {
|
|
19
|
+ if (Character.toString(e.charAt(e.length() - 1)).equals("y") ||
|
|
20
|
+ Character.toString(e.charAt(e.length() - 1)).equals("z")) {
|
|
21
|
+ count++;
|
|
22
|
+ }
|
|
23
|
+ }
|
|
24
|
+ return count;
|
15
|
25
|
}
|
16
|
26
|
|
17
|
27
|
/**
|
|
@@ -24,7 +34,7 @@ public class StringsAndThings {
|
24
|
34
|
* withoutString("Hello there", "x") // Should return "Hello there"
|
25
|
35
|
*/
|
26
|
36
|
public String withoutString(String base, String remove){
|
27
|
|
- return null;
|
|
37
|
+ return base.replace(remove, "");
|
28
|
38
|
}
|
29
|
39
|
|
30
|
40
|
/**
|
|
@@ -36,7 +46,26 @@ public class StringsAndThings {
|
36
|
46
|
* equalIsNot("noisxxnotyynotxisi") // Should return true
|
37
|
47
|
*/
|
38
|
48
|
public Boolean equalIsNot(String input){
|
39
|
|
- return null;
|
|
49
|
+ int isCount = 0;
|
|
50
|
+ int isIdx = 0;
|
|
51
|
+ while (isIdx != -1) {
|
|
52
|
+ isIdx = input.indexOf("is", ++isIdx);
|
|
53
|
+ if (isIdx != -1) {
|
|
54
|
+ isCount++;
|
|
55
|
+ isIdx++;
|
|
56
|
+ }
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ int notCount = 0;
|
|
60
|
+ isIdx = 0;
|
|
61
|
+ while (isIdx != -1) {
|
|
62
|
+ isIdx = input.indexOf("not", ++isIdx);
|
|
63
|
+ if (isIdx != -1) {
|
|
64
|
+ notCount++;
|
|
65
|
+ isIdx++;
|
|
66
|
+ }
|
|
67
|
+ }
|
|
68
|
+ return isCount == notCount;
|
40
|
69
|
}
|
41
|
70
|
|
42
|
71
|
/**
|
|
@@ -47,7 +76,7 @@ public class StringsAndThings {
|
47
|
76
|
* gHappy("xxggyygxx") // Should return false
|
48
|
77
|
*/
|
49
|
78
|
public Boolean gIsHappy(String input){
|
50
|
|
- return null;
|
|
79
|
+ return !input.replaceAll("gg+", "").contains("g");
|
51
|
80
|
}
|
52
|
81
|
|
53
|
82
|
|
|
@@ -59,6 +88,14 @@ public class StringsAndThings {
|
59
|
88
|
* countTriple("a") // Should return 0
|
60
|
89
|
*/
|
61
|
90
|
public Integer countTriple(String input){
|
62
|
|
- return null;
|
|
91
|
+ int count = 0;
|
|
92
|
+
|
|
93
|
+ for(int i = 0; i <= input.length() - 3; i++) {
|
|
94
|
+ if(input.charAt(i) == input.charAt(i+1) &&
|
|
95
|
+ input.charAt(i) == input.charAt(i+2))
|
|
96
|
+ count++;
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ return count;
|
63
|
100
|
}
|
64
|
101
|
}
|