Sort by

recency

|

5177 Discussions

|

  • + 0 comments

    Ussing operator overloading for fun, we all know it is not necessary.

    string operator*(const std::string& str, int count){
        std::string result = "";
        for (int i = 0; i < count; ++i) {
            result += str;
        }
        return result;
    }
    
    string operator*(int count, const string& str) {
        return str * count;
    }
    
    void staircase(int n) {
        int steps = n;
        while (n-->0) {
            cout<<" "s*n + "#"s*(steps-n)<<endl;
        }
    }
    
  • + 0 comments

    for (int i = 1; i <= n; i++) { string bosluklar = new string(' ', n - i); string kareler = new string('#', i); Console.WriteLine(bosluklar + kareler); }

  • + 0 comments

    def staircase(n):
    for i in range(1,n+1):
    print (("#"*i).rjust(n," "))

  • + 0 comments
    Here is my solution in java, time complexity O(n^2)`
    
    public static void staircase(int n) {
        // Write your code here
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {   
                if(j<n-(i+1))
                System.out.print(" ");
                else
                System.out.print("#");
            }
            System.out.println();
        }
        }
    

    `

  • + 0 comments

    Here is my solution for javascript:

    function staircase(n) {
        
        let star = ""
        for (let i = 0; i < n ; i++) {
            
            for (let j = n - 1; j > i; j--) {
                    star += " ";
            }
    
            for (let k = i; k >= 0; k--) {
                star += "#";
            }
            
            star += "\n";  
        }
        console.log(star)
    
    }