首页 > TAG信息列表 > StreamChecker

[LeetCode] 1032. Stream of Characters 字符流

Implement the StreamChecker class as follows: StreamChecker(words): Constructor, init the data structure with the given words. query(letter): returns true if and only if for some k >= 1, the last k characters queried (in order from oldest to newest, i

LeetCode 1032. Stream of Characters

原题链接在这里:https://leetcode.com/problems/stream-of-characters/ 题目: Implement the StreamChecker class as follows: StreamChecker(words): Constructor, init the data structure with the given words. query(letter): returns true if and only if for some k >=

leetcode 1032. Stream of Characters

用字典树即可解决。首先在init的时候,把words中所有word逆置后存入字典树中;在query的时候,也有逆序的方式记录所有历史query过的值,同时判断其前缀是否存在于字典树中即可。 function Node() { this.children = {} } class StreamChecker { constructor(wor