Kris Blassingame 6 years ago
parent
commit
be0e3cf6f3

+ 51
- 22
src/main/java/io/zipcoder/StringsAndThings.java View File

7
      * but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic
7
      * but not the 'y' in "yellow" (not case sensitive). We'll say that a y or z is at the end of a word if there is not an alphabetic
8
      * letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
8
      * letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
9
      * example : countYZ("fez day"); // Should return 2
9
      * example : countYZ("fez day"); // Should return 2
10
-     *           countYZ("day fez"); // Should return 2
11
-     *           countYZ("day fyyyz"); // Should return 2
10
+     * countYZ("day fez"); // Should return 2
11
+     * countYZ("day fyyyz"); // Should return 2
12
      */
12
      */
13
-    public Integer countYZ(String input){
14
-        return null;
13
+    public Integer countYZ(String input) {
14
+        int counter = 0;
15
+
16
+        String[] strArr = input.split(" ");
17
+        for (String word : strArr) {
18
+            if (word.endsWith("y") || word.endsWith("z")) {
19
+                counter++;
20
+            }
21
+        }
22
+        return counter;
15
     }
23
     }
16
 
24
 
17
     /**
25
     /**
18
      * Given two strings, base and remove, return a version of the base string where all instances of the remove string have
26
      * Given two strings, base and remove, return a version of the base string where all instances of the remove string have
19
      * been removed (not case sensitive). You may assume that the remove string is length 1 or more.
27
      * been removed (not case sensitive). You may assume that the remove string is length 1 or more.
20
      * Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
28
      * Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
21
-     *
29
+     * <p>
22
      * example : withoutString("Hello there", "llo") // Should return "He there"
30
      * example : withoutString("Hello there", "llo") // Should return "He there"
23
-     *           withoutString("Hello there", "e") //  Should return "Hllo thr"
24
-     *           withoutString("Hello there", "x") // Should return "Hello there"
31
+     * withoutString("Hello there", "e") //  Should return "Hllo thr"
32
+     * withoutString("Hello there", "x") // Should return "Hello there"
25
      */
33
      */
26
-    public String withoutString(String base, String remove){
27
-        return null;
34
+    public String withoutString(String base, String remove) {
35
+
36
+        String str = base.replace(remove, "");
37
+
38
+
39
+        return str;
28
     }
40
     }
29
 
41
 
42
+
30
     /**
43
     /**
31
      * Given a string, return true if the number of appearances of "is" anywhere in the string is equal
44
      * Given a string, return true if the number of appearances of "is" anywhere in the string is equal
32
      * to the number of appearances of "not" anywhere in the string (case sensitive)
45
      * to the number of appearances of "not" anywhere in the string (case sensitive)
33
-     *
46
+     * <p>
34
      * example : equalIsNot("This is not")  // Should return false
47
      * example : equalIsNot("This is not")  // Should return false
35
-     *           equalIsNot("This is notnot") // Should return true
36
-     *           equalIsNot("noisxxnotyynotxisi") // Should return true
48
+     * equalIsNot("This is notnot") // Should return true
49
+     * equalIsNot("noisxxnotyynotxisi") // Should return true
37
      */
50
      */
38
-    public Boolean equalIsNot(String input){
39
-        return null;
51
+    public Boolean equalIsNot(String input) {
52
+
53
+
54
+        int countIs = (input.split("is", -1).length) - 1;
55
+        int countNot = (input.split("not", -1).length) - 1;
56
+
57
+        if (countIs == countNot) {
58
+            return true;
59
+        }
60
+        return false;
40
     }
61
     }
41
 
62
 
63
+
42
     /**
64
     /**
43
      * We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right.
65
      * We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right.
44
      * Return true if all the g's in the given string are happy.
66
      * Return true if all the g's in the given string are happy.
45
      * example : gHappy("xxggxx") // Should return  true
67
      * example : gHappy("xxggxx") // Should return  true
46
-     *           gHappy("xxgxx") // Should return  false
47
-     *           gHappy("xxggyygxx") // Should return  false
68
+     * gHappy("xxgxx") // Should return  false
69
+     * gHappy("xxggyygxx") // Should return  false
48
      */
70
      */
49
-    public Boolean gIsHappy(String input){
50
-        return null;
51
-    }
71
+    public Boolean gIsHappy(String input) {
72
+        // int countG = (input.split("g", -1).length) - 1;
73
+        int countGG = (input.split("gg", -1).length) - 1;
52
 
74
 
75
+        if (countGG > 0) {
76
+            return true;
77
+        }
78
+        return false;
79
+    }
53
 
80
 
54
     /**
81
     /**
55
      * We'll say that a "triple" in a string is a char appearing three times in a row.
82
      * We'll say that a "triple" in a string is a char appearing three times in a row.
56
      * Return the number of triples in the given string. The triples may overlap.
83
      * Return the number of triples in the given string. The triples may overlap.
57
      * example :  countTriple("abcXXXabc") // Should return 1
84
      * example :  countTriple("abcXXXabc") // Should return 1
58
-     *            countTriple("xxxabyyyycd") // Should return 3
59
-     *            countTriple("a") // Should return 0
85
+     * countTriple("xxxabyyyycd") // Should return 3
86
+     * countTriple("a") // Should return 0
60
      */
87
      */
61
-    public Integer countTriple(String input){
88
+    public Integer countTriple(String input) {
89
+        
62
         return null;
90
         return null;
63
     }
91
     }
64
 }
92
 }
93
+

BIN
target/classes/io/zipcoder/StringsAndThings.class View File


BIN
target/test-classes/io/zipcoder/StringsAndThingsTest.class View File