Problem Statement
A string is called a square if it can be created by concatenating two copies of the same string.
For example, "CANCAN" is a square because it consists of two copies of the string "CAN".
Other squares include "AA", "ZZZZ", and "BERIBERI".
The strings "AAAAA" and "HAHAHA" are not squares.
You are given a String S. Return "square" (quotes for clarity) if there is a string T such that S = T + T. Otherwise, return "not square". Note that the return value is case-sensitive.
You are given a String S. Return "square" (quotes for clarity) if there is a string T such that S = T + T. Otherwise, return "not square". Note that the return value is case-sensitive.
Definition
- Class:
- DoubleString
- Method:
- check
- Parameters:
- String
- Returns:
- String
- Method signature:
- String check(String S)
- (be sure your method is public)
Constraints
- The length of S will be between 1 and 50, inclusive.
- Each character in S will be an uppercase letter ('A'-'Z').
Examples
"MAZAIMAZAI"
Returns: "square"
If T is "MAZAI", T+T will be "MAZAIMAZAI"."MAMAZAIZAI"
Returns: "not square"
In this case, there is no string T for which T+T will be S."IOI"
Returns: "not square"
The length of S is odd, so it's impossible to make S by concatenating the same string twice."AA"
Returns: "square"
T will be "A"."ABCCBA"
Returns: "not square"
"Y"
Returns: "not square"