Created
March 13, 2016 02:31
-
-
Save jianminchen/e4863f946534124c7229 to your computer and use it in GitHub Desktop.
HackerRank - Alternating Characters - https://www.hackerrank.com/challenges/alternating-characters
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AlternatingCharacters | |
{ | |
/* | |
* Alternating Characters | |
* | |
* https://www.hackerrank.com/challenges/alternating-characters | |
* | |
* | |
*/ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string s1 = Console.ReadLine(); | |
int n = Convert.ToInt16(s1); | |
for(int i=0;i<n;i++) | |
{ | |
string s = Console.ReadLine(); | |
Console.WriteLine(countDeletion(s)); | |
} | |
} | |
/* | |
* string.Length >= 1 | |
*/ | |
public static int countDeletion(string s) | |
{ | |
if (s == null || s.Length == 0) | |
return 0; | |
int count = 0; | |
for(int i=1; i< s.Length; i++) | |
{ | |
if (s[i] == s[i - 1]) | |
count++; | |
} | |
return count; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment