Algorithm/HackerRank
[Warm Up] Staircase
SamusesApple
2023. 5. 11. 14:02
728x90
문제 설명:
Staircase detail
This is a staircase of size : n = 4
#
##
###
####
Its base and height are both equal to n. It is drawn using # symbols and spaces. The last line is not preceded by any spaces.
Write a program that prints a staircase of size n.
내 풀이:
func staircase(n: Int) -> Void {
for i in 1...n {
// 띄어쓰기 먼저 반복 후, 마지막에 #가 출력되야 함
print(String(repeating: " ", count: n - i) + String(repeating: "#", count: i))
}
}
728x90