Skip to content

All test cases passed #43

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 1 commit 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
56 changes: 50 additions & 6 deletions src/main/java/io/zipcoder/StringsAndThings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.zipcoder;


import java.sql.SQLOutput;
import java.util.Locale;

/**
* @author tariq
*/
Expand All @@ -15,7 +18,14 @@ public class StringsAndThings {
* countYZ("day fyyyz"); // Should return 2
*/
public Integer countYZ(String input){
return null;
int count = 0;
String[] words = input.split(" ");
for(int i = 0; i < words.length; i++){
if(words[i].charAt(words[i].length() - 1) == 'y' || words[i].charAt(words[i].length() - 1) == 'z'){
count += 1;
}
}
return count;
}

/**
Expand All @@ -28,7 +38,7 @@ public Integer countYZ(String input){
* removeString("Hello there", "x") // Should return "Hello there"
*/
public String removeString(String base, String remove){
return null;
return base.replaceAll(remove, "");
}

/**
Expand All @@ -40,7 +50,25 @@ public String removeString(String base, String remove){
* containsEqualNumberOfIsAndNot("noisxxnotyynotxisi") // Should return true
*/
public Boolean containsEqualNumberOfIsAndNot(String input){
return null;
int isCount = 0;
int notCount = 0;
int indexOf = input.indexOf("not");
String currentString = input;

while(indexOf >= 0){
currentString = currentString.replaceFirst("not", "");
indexOf = currentString.indexOf("not");
notCount++;
}
currentString = input;
indexOf = currentString.indexOf("is");
while(indexOf >= 0){
currentString = currentString.replaceFirst("is", "");
indexOf = currentString.indexOf("is");
isCount++;
System.out.println("found is");
}
return isCount == notCount;
}

/**
Expand All @@ -51,7 +79,15 @@ public Boolean containsEqualNumberOfIsAndNot(String input){
* gHappy("xxggyygxx") // Should return false
*/
public Boolean gIsHappy(String input){
return null;
for(int i = 1; i < input.length(); i++){
if(input.charAt(i) == 'g'){
//if the current character being examined is NOT the last or first character
if(input.charAt(i - 1) != 'g' && input.charAt(i + 1) != 'g'){
return false;
}
}
}
return true;
}


Expand All @@ -62,7 +98,15 @@ public Boolean gIsHappy(String input){
* countTriple("xxxabyyyycd") // Should return 3
* countTriple("a") // Should return 0
*/
public Integer countTriple(String input){
return null;
public Integer countTriple(String input){ //abcXXXabc 9 6
int count = 0;
for(int i = 0; i < input.length() - 3; i++){
if(input.charAt(i) == input.charAt(i + 1) &&
input.charAt(i) == input.charAt(i + 2)){
count += 1;
}
}
return count;
}
}

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.