goden1602

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

面试题 16.02.单词频率

1. 题目描述

设计一个方法,找出任意指定单词在一本书中的出现频率。

你的实现应该支持如下操作:

  • WordsFrequency(book) 构造函数,参数为字符串数组构成的一本书
  • get(word) 查询指定单词在书中出现的频率 示例:
WordsFrequency wordsFrequency = new WordsFrequency({"i", "have", "an", "apple", "he", "have", "a", "pen"});
wordsFrequency.get("you"); //返回0,"you"没有出现过
wordsFrequency.get("have"); //返回2,"have"出现2次
wordsFrequency.get("an"); //返回1
wordsFrequency.get("apple"); //返回1
wordsFrequency.get("pen"); //返回1

提示:

  • book[i] 中只包含小写字母
  • 1 <= book.length <= 100000
  • 1 <= book[i].length <= 10
  • get 函数的调用次数不会超过100000

标签 设计 字典树 数组 哈希表 字符串

2. 解题

  1. 哈希表
  2. Trie树

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WordsFrequency

type WordsFrequency struct {
	// contains filtered or unexported fields
}

func Constructor

func Constructor(book []string) WordsFrequency

func (*WordsFrequency) Get

func (this *WordsFrequency) Get(word string) int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL