Created
February 21, 2021 08:07
-
-
Save samarthsewlani/843a6bc5e55048308c43b50084d4fac6 to your computer and use it in GitHub Desktop.
Alternating Characters HackerRank Solution
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
def alternatingCharacters(s): | |
count=0 | |
for i in range(1,len(s)): # We start from 1 as there is no previous charcter for 0th index | |
if s[i]==s[i-1]: # If current character is same as previous charcter | |
count+=1 | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment