My 24ms unreadable solution


  • 1
    S
    #! /bin/bash
    export LC_ALL=C
    col_num=$(awk -F' ' 'NR==1{print NF}' file.txt)
    awk -F' ' -v n_col=$col_num 'BEGIN{for(i=1;i<=n_col;++i) line[i]=""}{for(i=1;i<=NF;++i){line[i]=sprintf("%s %s", line[i], $i)}}END{for(i=1;i<=n_col;++i) print line[i]}'  file.txt | sed "s;^ ;;g"

Log in to reply
 

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