Skip to content

strings and things #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 74 additions & 18 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.zipcoder;


import java.util.Locale;

/**
* @author tariq
*/
Expand All @@ -11,48 +13,95 @@ public class StringsAndThings {
* 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
* letter immediately following it. (Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
* example : countYZ("fez day"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
* countYZ("day fez"); // Should return 2
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
public Integer countYZ(String input) {
int result = 0;
String[] words = input.split(" ");
for (String word : words
) {
if (word.endsWith("y") || word.endsWith("z")) {
result += 1;
}

}
return result;
}

/**
* Given two strings, base and remove, return a version of the base string where all instances of the remove string have
* been removed (not case sensitive). You may assume that the remove string is length 1 or more.
* Remove only non-overlapping instances, so with "xxx" removing "xx" leaves "x".
*
* <p>
* example : removeString("Hello there", "llo") // Should return "He there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
* removeString("Hello there", "e") // Should return "Hllo thr"
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
public String removeString(String base, String remove) {
String result = "";
result = base.replace(remove, "");
return result;
}

/**
* Given a string, return true if the number of appearances of "is" anywhere in the string is equal
* to the number of appearances of "not" anywhere in the string (case sensitive)
*
* <p>
* example : containsEqualNumberOfIsAndNot("This is not") // Should return false
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
* containsEqualNumberOfIsAndNot("This is notnot") // Should return true
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
public Boolean containsEqualNumberOfIsAndNot(String input) {
Boolean result = false;
String[] inputSplitIntoLetters = input.split("");
int countOfIs=0;
int countOfNot=0;
for(int i=0;i<inputSplitIntoLetters.length-1;i++){
if(inputSplitIntoLetters[i].equals("i")&&inputSplitIntoLetters[i+1].equals("s")){
countOfIs++;
}
if(inputSplitIntoLetters[i].equals("n")&&inputSplitIntoLetters[i+1].equals("o")&&inputSplitIntoLetters[i+2].equals("t")){
countOfNot++;
}
}
if(countOfIs == countOfNot){
result=true;
}

return result;
}









/**
* We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right.
* Return true if all the g's in the given string are happy.
* example : gHappy("xxggxx") // Should return true
* gHappy("xxgxx") // Should return false
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
}
public Boolean gIsHappy(String input) {
Boolean result = false;
String[] letter = input.split("");
for (int i = 0; i < letter.length - 1; i++) {
if (letter[i].equals("g") && letter[i + 1].equals("g")) {
result = true;
}
if (i > 0) {
if (letter[i].equals("g") && letter[i - 1].equals("g")) {
result = true;
}
}
}
return result;
}


/**
Expand All @@ -63,6 +112,13 @@ public Boolean gIsHappy(String input){
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
int result=0;
String[] letter = input.split("");
for(int i=0;i<letter.length-1;i++){
if(letter[i].equals(letter[i+1]) && letter[i+1].equals(letter[i+2])){
result++;
}
}
return result;
}
}
Binary file added target/classes/io/zipcoder/StringsAndThings.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.