JAVA | Trie
\nclass Solution {\n    int res=0;\n    public int numMatchingSubseq(String s, String[] words) {\n        TrieNode root=new TrieNode(\'#\');\n        for(String
```\nclass Solution {\n    int res=0;\n    public int numMatchingSubseq(String s, String[] words) {\n        TrieNode root=new TrieNode(\'#\');\n        for(String w:words){\n            parseTrieNode(w,root);\n        }\n        helper(s,-1,root);\n        return res;\n    }\n    \n    private void parseTrieNode(String w,TrieNode root){\n        TrieNode node=root;\n        for(char c:w.toCharArray()){\n            node=node.add(c);\n        }\n        node.counts++;\n    }\n    \n    private void helper(String s,int p,TrieNode node){\n        res+=node.counts;\n        for(TrieNode tn:node.getTrieNodes()){\n            if(tn==null){\n                continue;\n            }\n            int p1=s.indexOf(tn.c,p+1);\n            if(p1<0){\n                continue;\n            }\n            helper(s,p1,tn);\n        }\n    }\n}\n\nclass TrieNode{\n    int counts=0;\n    char c;\n    TrieNode v[]=new TrieNode[26];\n    \n    public TrieNode(char c){\n        this.c=c;\n    }\n    public TrieNode add(char c){\n        int a=c-\'a\';\n        if(v[a]==null){\n            v[a]=new TrieNode(c);\n        }        \n        return v[a];\n    }\n    \n    public TrieNode[] getTrieNodes(){\n        return v;\n    }\n}\n```
['Java']