第一题 [250分]
Problem Statement
You want to buy two neighboring tickets in the first row of the theater so that one of the tickets is as far from the aisles as possible.
You will be given a String describing the first row of the theater where '.' represents an empty seat and 'X' represents an occupied seat. Your task is to return the index (from 0) of the empty seat that is furthest from the aisles (the two ends of the String) and is also next to an empty seat. If there are multiple possible seats, return the one with the smallest index. Return -1 if there are no seats that satisfy your requirements.
Definition
Class:
TheaterVisit
Method:
chooseSeat
Parameters:
string
Returns:
int
Method signature:
int chooseSeat(string row)
(be sure your method is public)
Constraints
-
row will contain between 1 and 50 characters, inclusive.
-
Each character in row will be either '.' or 'X'.
Examples
0)
"....."
Returns: 2
You can buy either tickets with indexes 1 and 2 or tickets with indexes 2 and 3.
1)
"......"
Returns: 2
2)
"..X..."
Returns: 3
You should buy tickets with indexes 3 and 4.
3)
".X.X..."
Returns: 4
4)
"X.XX.X"
Returns: -1
5)
".."
Returns: 0