Problem Statement
Alien Fred wants to destroy the Earth, but he forgot the password that activates the planet destroyer.
You are given a String S. Fred remembers that the correct password can be obtained from S by erasing exactly one character.
Return the number of different passwords Fred needs to try.
Definition
- Class:
- AlienAndPassword
- Method:
- getNumber
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getNumber(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 uppercase English letter ('A'-'Z').
Examples
"A"
Returns: 1
In this case, the only password Fred needs to try is an empty string."ABA"
Returns: 3
The following three passwords are possible in this case: "BA", "AA", "AB"."AABACCCCABAA"
Returns: 7
"AGAAGAHHHHFTQLLAPUURQQRRRUFJJSBSZVJZZZ"
Returns: 26
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
Returns: 1
Regardless of which character we erase, we will always obtain the same string. Thus there is only one possible password: the string that consists of 49 'Z's.