Skip to content

Commit 7dea02f

Browse files
committed
Add: Word Frequency
1 parent 78e07f7 commit 7dea02f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Diff for: problems/word-frequency/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<!--|@home https://github.com/openset/leetcode |-->
66
<!--+----------------------------------------------------------------------+-->
77

8+
[< Previous](https://github.com/openset/leetcode/tree/master/problems/number-of-1-bits "Number of 1 Bits")
9+
                
10+
[Next >](https://github.com/openset/leetcode/tree/master/problems/valid-phone-numbers "Valid Phone Numbers")
11+
812
## 192. Word Frequency (Medium)
913

1014
<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>

Diff for: problems/word-frequency/word_frequency.bash

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# Read from the file words.txt and output the word frequency list to stdout.
4+
5+
awk '{for(i=1;i<=NF;i++) a[$i]++} END {for(k in a) print k,a[k]}' words.txt | sort -k2 -nr

Diff for: problems/word-frequency/words.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
the day is sunny the the
2+
the sunny is is

0 commit comments

Comments
 (0)