Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int substrCount(String S[0...n-1]){
- int count = 0;
- for (int i = 0; i<=n-2; i++) {
- for (int j=i+1; j<i+2; j++) {
- if ((S[i] == 'B' && S[j] == 'C' ) || (S[i] == 'C' && S[j] == 'B')) {
- count = count + 1;
- }
- }
- }
- }
- static int substrCount( String str) {
- int count=0;
- for (int i=0; i<str.length()-1; i++)
- {
- boolean bc = (str.charAt(i) == 'B' && str.charAt(i+1) == 'C');
- boolean cb = (str.charAt(i) == 'C' && str.charAt(i+1) == 'B');
- if (bc || cb) {
- count++;
- }
- }
- return count;
- }
- "ACBAA" gives result 1
- "ABCBA" gives result 2
- "BCBCB" gives result 4
- "BBBBB" gives result 0
Add Comment
Please, Sign In to add comment