문제
Draw a hollow square of side size: the first and last rows are all *, and the rows in between have * only at the two ends with spaces inside.
Implement hollow_square(size).
Input
size: The side length.
Output
Return the rows from top to bottom.
제약 조건
1 ≤ size ≤ 50
예시
예시 1
입력:
size = 4
예상 출력:
expected = ["****", "* *", "* *", "****"]
입력:
long long size = 4;
예상 출력:
std::vector<std::string> expected = {"****", "* *", "* *", "****"};
입력:
long size = 4;
예상 출력:
string[] expected = new string[] {"****", "* *", "* *", "****"};
설명
Rows are "****", "* *", "* *", "****".
예시 2
입력:
size = 1
예상 출력:
expected = ["*"]
입력:
long long size = 1;
예상 출력:
std::vector<std::string> expected = {"*"};
입력:
long size = 1;
예상 출력:
string[] expected = new string[] {"*"};
설명
A 1×1 square is a single "*".
접근 방법
먼저 스스로 풀어 본 뒤 힌트를 하나씩 열어 보세요.
힌트 1
The border is filled, while the inside stays empty.
힌트 2
Treat the first and last rows differently from the middle rows.
힌트 3
For size one, the single cell is both border and corner, so it must be filled.
예상 복잡도
O(size^2) time, O(size^2) extra space
참고 자료
이 문제는 CodeUtility에 맞게 수정되었습니다. 위의 설명과 제약 조건을 기준으로 풀어 주세요.