Created
August 19, 2016 15:45
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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