Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/e4863f946534124c7229 to your computer and use it in GitHub Desktop.
Save jianminchen/e4863f946534124c7229 to your computer and use it in GitHub Desktop.
HackerRank - Alternating Characters - https://www.hackerrank.com/challenges/alternating-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