My solution by sort + tr + sed


  • 0
    4
    # Read from the file words.txt and output the word frequency list to stdout.
    cat words.txt| tr -s " " "\n" |sort| uniq -c | sort -rk1| sed "s/\(.*\) \(.*\)/\2\1/" | tr -s " "

Log in to reply
 

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