Skip to content

Commit a8d98e3

Browse files
authored
Create alternating-characters solution
1 parent dd5f9f6 commit a8d98e3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://www.hackerrank.com/challenges/alternating-characters/problem
2+
int alternatingCharacters(string s) {
3+
int len = s.size();
4+
if(len <=1 )
5+
return 0;
6+
7+
int solution = 0;
8+
9+
for(int i =0; i< len-1; i++)
10+
{
11+
if(s[i] == s[i+1])
12+
solution+=1;
13+
}
14+
return solution;
15+
16+
}

0 commit comments

Comments
 (0)