We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this code also works well. time complexity is O(N).
public static String repeat(String str, int times) {
return new String(new char[times]).replace("\0", str);
}
public static void main(String[] args) {
Scanner scannerObj = new Scanner(System.in);
int n = scannerObj.nextInt();
for(int i = n-1; i >= 0; i--) {
System.out.print(repeat(" ", i));
System.out.println(repeat("#", n-i));
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Staircase
You are viewing a single comment's thread. Return to all comments →
this code also works well. time complexity is O(N).