Skip to content

Commit

Permalink
leetcode: Add 0192
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Jun 2, 2024
1 parent a0f5148 commit 5fad71c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/leetcode/0192.word-frequency/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "lc-0192-word-frequency"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
4 changes: 4 additions & 0 deletions src/leetcode/0192.word-frequency/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#

[问题描述](../problems/)
23 changes: 23 additions & 0 deletions src/leetcode/0192.word-frequency/solve.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions src/leetcode/0192.word-frequency/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024 Xu Shaohua <[email protected]>. 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);
}
}
2 changes: 2 additions & 0 deletions src/leetcode/0192.word-frequency/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
the day is sunny the the
the sunny is is

0 comments on commit 5fad71c

Please sign in to comment.