Einfach 3 gelöst 100.0% Erfolgsquote

Pyramid Rows

Draw a right-aligned pyramid of # blocks.

Das lernst du

  • Build rows with padding and blocks
  • Compute spaces and symbols per row
  • Return lines as a list

Problem

Übersetzung anzeigen

Draw a right-aligned pyramid like the one in Super Mario: row i (counting from 1) has height − i spaces followed by i # characters.

Implement pyramid_rows(height).

Input

height: The number of rows.

Output

Return the rows from top to bottom.

Einschränkungen

0 ≤ height ≤ 50

Beispiele

Beispiel 1
Eingabe:
height = 3

Erwartete Ausgabe:
expected = ["  #", " ##", "###"]
Eingabe:
long long height = 3;

Erwartete Ausgabe:
std::vector<std::string> expected = {"  #", " ##", "###"};
Eingabe:
long height = 3;

Erwartete Ausgabe:
string[] expected = new string[] {"  #", " ##", "###"};

Erläuterung

Rows are " #", " ##" and "###": each row has one more block and one less space.

Beispiel 2
Eingabe:
height = 1

Erwartete Ausgabe:
expected = ["#"]
Eingabe:
long long height = 1;

Erwartete Ausgabe:
std::vector<std::string> expected = {"#"};
Eingabe:
long height = 1;

Erwartete Ausgabe:
string[] expected = new string[] {"#"};

Erläuterung

A single row with one block: "#".

So gehst du vor

Versuch es zuerst allein und öffne dann einen Hinweis nach dem anderen.

Hinweis 1

Each row combines leading spaces with a growing run of hash characters.

Hinweis 2

Build rows one by one from top to bottom so the alignment stays correct.

Hinweis 3

If the height is zero, return no rows rather than an empty-looking pyramid.

Erwartete Komplexität

O(height^2) time, O(height^2) extra space

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Die beste bestandene Lösung jedes Coders. Schnellere, sparsamere und besser bewertete Lösungen stehen weiter oben.

# Coder Sprache Zeit Speicher KI-Bewertung Lösung
1 HJhettory Jurash Python 778 ms - 4/5 Code ansehen
2 LMLaura Mahlow Python 814 ms - 4/5 Code ansehen
3 KKKaneki Ken Python 849 ms - 5/5 Code ansehen

Von anderen lernen

Community-Lösungen

Achtung Spoiler: 3 vollständige Lösungen unten Versuche es zuerst selbst zu lösen. Du kannst trotzdem einen Blick auf den Code und die KI-Reviews anderer Entwickler werfen. Melde dich an und löse die Aufgabe, um an der Diskussion teilzunehmen.