Problem Statement
You are given an image described in String[] image. Different characters in image represent pixels of different colors. (For example, each 'A' is a red pixel, each 'B' is a blue pixel, and so on.) You want to determine if the image is symmetric, either horizontally or vertically. Return 0 if there is no symmetry, 1 if the image is symmetric in only a single direction, or 2 if it is symmetric both horizontally and vertically.
Definition
- Class:
- SymmetricImage
- Method:
- countDirections
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int countDirections(String[] image)
- (be sure your method is public)
Constraints
- image will contain between 1 and 50 elements, inclusive.
- Each element of image will contain between 1 and 50 characters, inclusive.
- Each element of image will be the same length.
- Each character of each element of image will be an uppercase letter ('A'-'Z').
Examples
{ "AAA", "BBB" }Returns: 1
The image is symmetric horizontally, but not vertically.{ "ABCDE", "ABCDE", "ABCDE" }Returns: 1
Here we have vertical symmetry only.{ "ABA", "CDC", "ABA" }Returns: 2
Symmetry in both directions.{ "ABC" }Returns: 1
With only a single row of pixels, we are guaranteed vertical symmetry.{ "AB", "CD" }Returns: 0
No symmetry at all.