• + 0 comments

    My Java solution with o(n^2) time complexity and o(1) space complexity:

    public static void staircase(int n) {
            // goal: print staircase with a base of size n
            for(int i = 1; i <= n; i++) System.out.println(" ".repeat(n - i) + "#".repeat(i));
        }