샘성의 iOS 개발 일지

[Warm Up] Staircase 본문

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

'Algorithm > HackerRank' 카테고리의 다른 글

[Implementation] Apple and Orange  (0) 2023.05.12
[Implementation] Grading Students  (0) 2023.05.12
[Warm Up] Time Conversion  (0) 2023.05.11
[Warm Up] Birthday Cake Candles  (0) 2023.05.11
[Warm Up] Diagonal Difference  (0) 2023.05.11