Skip to content

Instantly share code, notes, and snippets.

@sbsatter
Created August 19, 2016 15:45
Show Gist options
  • Save sbsatter/5241f203ab5f10042ac10ef6403097db to your computer and use it in GitHub Desktop.
Save sbsatter/5241f203ab5f10042ac10ef6403097db to your computer and use it in GitHub Desktop.
http://codingbat.com/prob/p154048 Count overlapping pairs in the form AxA where A has a pair!
public int countPairs(String str) {
if(str.length()<3)
return 0;
String sub=str.substring(0,3);
int n= checkSubstringForPair(sub);
return n+countPairs(str.substring(1,str.length()));
}
public int checkSubstringForPair(String sub){
if(sub.charAt(0)==sub.charAt(2))
return 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment