ios – LeetCode Staircase Solution


Problem

This is a staircase of size n = 4;

   #
  ##
 ###
####

Its base and height are both equal to . It is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Constraints :
0<n<=100

Output Format: Print a staircase of size using # symbols and spaces.

Note: The last line must have spaces in it.

Explanation: The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n = 4.

Solution

func staircase(n: Int) -> Void {
   for index in 1...n {
     print("\(String(repeating: " ", count: n - index))\(String(repeating: "#", count: index))")
   }
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img