one lime solution in 12ms


  • 0
    C
     sed "s/ /\n/g" words.txt|grep -v -P "^$"|sort|uniq -c|sort -n -r|awk '{print $2, $1}'
    

    In fact I was trying to use sed "s/\s\+/\n/g" words.txt to avoid using grep, but it didn't work.
    Any one can help me figure out the mistake?
    Thanks a lot!


Log in to reply
 

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