diff --git a/src/leetcode/0192.word-frequency/Cargo.toml b/src/leetcode/0192.word-frequency/Cargo.toml new file mode 100644 index 000000000..c18812147 --- /dev/null +++ b/src/leetcode/0192.word-frequency/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "lc-0192-word-frequency" +version = "0.1.0" +edition = "2021" +publish = false + +[dependencies] diff --git a/src/leetcode/0192.word-frequency/index.md b/src/leetcode/0192.word-frequency/index.md new file mode 100644 index 000000000..77a618ba8 --- /dev/null +++ b/src/leetcode/0192.word-frequency/index.md @@ -0,0 +1,4 @@ + +# + +[问题描述](../problems/) diff --git a/src/leetcode/0192.word-frequency/solve.sh b/src/leetcode/0192.word-frequency/solve.sh new file mode 100755 index 000000000..c7367b455 --- /dev/null +++ b/src/leetcode/0192.word-frequency/solve.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +#set -xe + +solution1() { + declare -A dict + for word in $(cat $1 | xargs); do + if [[ x${!dict["$word"]} == x"" ]]; then + dict["$word"]=0 + fi + dict["${word}"]=$((1 + dict["${word}"])) + done + for word in "${!dict[@]}"; do + echo "${word} ${dict["${word}"]}" + done +} + +solution2() { + cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -nr | awk '{print $2, $1}' +} + +#solution1 words.txt +solution2 diff --git a/src/leetcode/0192.word-frequency/src/main.rs b/src/leetcode/0192.word-frequency/src/main.rs new file mode 100644 index 000000000..9edcfeb7d --- /dev/null +++ b/src/leetcode/0192.word-frequency/src/main.rs @@ -0,0 +1,27 @@ +// Copyright (c) 2024 Xu Shaohua . All rights reserved. +// Use of this source is governed by General Public License that can be found +// in the LICENSE file. + +pub fn solution1() { + todo!(); +} + +pub type SolutionFn = fn(); + +fn check_solution(_func: SolutionFn) { + todo!(); +} + +fn main() { + check_solution(solution1); +} + +#[cfg(test)] +mod tests { + use super::{check_solution, solution1}; + + #[test] + fn test_solution1() { + check_solution(solution1); + } +} diff --git a/src/leetcode/0192.word-frequency/words.txt b/src/leetcode/0192.word-frequency/words.txt new file mode 100644 index 000000000..18d52475f --- /dev/null +++ b/src/leetcode/0192.word-frequency/words.txt @@ -0,0 +1,2 @@ +the day is sunny the the +the sunny is is