TopcoderARCHIVE
Archive/Problems/DoubleLetterCount
SRM · Problem 17475

DoubleLetterCount

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given String s, consisting of all upper-case letters. A double-letter refers to two adjacent letters in the string being the same. Return the number of double-letters appearing in s.

Definition

Class:
DoubleLetterCount
Method:
count
Parameters:
String
Returns:
int
Method signature:
int count(String s)
(be sure your method is public)

Constraints

  • s will contain between 1 and 50 characters, inclusive.
  • Each character in s will be an upper-case ('A'-'Z') letter.
  • s will not contain any triple-letters.

Examples

  1. "MISS"
    Returns: 1
    The SS is a double letter.
  2. "COMMITTEE"
    Returns: 3
    M, T, and E all form double letters.
  3. "AABAAC"
    Returns: 2
    Notice that we count both instances of AA.
  4. "ABCDEFG"
    Returns: 0
    No double letters here.
  5. "AXXBCYWWYDEFZZ"
    Returns: 3
← All problems