My 28ms awk solution


  • 8
    T
    # Read from the file file.txt and print its transposed content to stdout.
    
    # using awk for this purpose
    awk '
        {
            for(i=1; i<=NF; i++)
            {   
                if(line[i] == "")
                {
                    line[i] = $i
                }
                else
                {
                    line[i] = line[i]" "$i
                }
            }
        }
        END{
             for(i=1; i<=NF; i++)
             {
                 print line[i]
             }
           }
        ' file.txt

  • 0
    K
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.