{"id":62142,"date":"2026-01-19T12:18:12","date_gmt":"2026-01-19T04:18:12","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/62142.html"},"modified":"2026-01-19T12:18:12","modified_gmt":"2026-01-19T04:18:12","slug":"java%e7%89%88leetcode%e7%83%ad%e9%a2%98100%e4%b9%8b%e5%ae%9e%e7%8e%b0-trie%ef%bc%88%e5%89%8d%e7%bc%80%e6%a0%91%ef%bc%89%ef%bc%9a%e4%bb%8e%e5%8e%9f%e7%90%86%e5%88%b0%e5%ae%9e%e6%88%98%e7%9a%84%e6%b7%b1","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/62142.html","title":{"rendered":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h2>Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;&#xff1a;\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790<\/h2>\n<p>\u6458\u8981&#xff1a;\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790 LeetCode \u70ed\u9898 100 \u4e2d\u7684\u7ecf\u5178\u9898\u76ee\u2014\u2014\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;\u3002\u6211\u4eec\u5c06\u4ece\u539f\u9898\u51fa\u53d1&#xff0c;\u9010\u6b65\u62c6\u89e3\u5176\u80cc\u540e\u7684\u7b97\u6cd5\u601d\u60f3\u3001\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1&#xff0c;\u5e76\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684 Java \u5b9e\u73b0\u4ee3\u7801\u3002\u6587\u7ae0\u6db5\u76d6\u65f6\u95f4\/\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u3001\u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3001\u76f8\u5173\u9898\u76ee\u63a8\u8350\u7b49\u6a21\u5757&#xff0c;\u65e8\u5728\u5e2e\u52a9\u8bfb\u8005\u5168\u9762\u638c\u63e1 Trie \u7684\u6838\u5fc3\u539f\u7406\u4e0e\u5de5\u7a0b\u5b9e\u8df5\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u539f\u9898\u56de\u987e<\/h3>\n<p>\u9898\u76ee\u540d\u79f0&#xff1a;\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;<br \/>\n\u9898\u76ee\u7f16\u53f7&#xff1a;LeetCode 208<br \/>\n\u96be\u5ea6\u7b49\u7ea7&#xff1a;\u4e2d\u7b49<\/p>\n<h4>\u9898\u76ee\u63cf\u8ff0<\/h4>\n<p>Trie&#xff08;\u53d1\u97f3\u7c7b\u4f3c \u201ctry\u201d&#xff09;\u6216\u8005\u8bf4 \u524d\u7f00\u6811 \u662f\u4e00\u79cd\u6811\u5f62\u6570\u636e\u7ed3\u6784&#xff0c;\u7528\u4e8e\u9ad8\u6548\u5730\u5b58\u50a8\u548c\u68c0\u7d22\u5b57\u7b26\u4e32\u6570\u636e\u96c6\u4e2d\u7684\u952e\u3002\u8fd9\u4e00\u6570\u636e\u7ed3\u6784\u6709\u76f8\u5f53\u591a\u7684\u5e94\u7528\u60c5\u666f&#xff0c;\u4f8b\u5982\u81ea\u52a8\u8865\u5168\u548c\u62fc\u5199\u68c0\u67e5\u3002<\/p>\n<p>\u8bf7\u4f60\u5b9e\u73b0 Trie \u7c7b&#xff1a;<\/p>\n<ul>\n<li>Trie() \u521d\u59cb\u5316\u524d\u7f00\u6811\u5bf9\u8c61\u3002<\/li>\n<li>void insert(String word) \u5411\u524d\u7f00\u6811\u4e2d\u63d2\u5165\u5b57\u7b26\u4e32 word\u3002<\/li>\n<li>boolean search(String word) \u5982\u679c\u5b57\u7b26\u4e32 word \u5728\u524d\u7f00\u6811\u4e2d&#xff0c;\u8fd4\u56de true&#xff08;\u5373&#xff0c;\u5728\u68c0\u7d22\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165&#xff09;&#xff1b;\u5426\u5219&#xff0c;\u8fd4\u56de false\u3002<\/li>\n<li>boolean startsWith(String prefix) \u5982\u679c\u4e4b\u524d\u5df2\u7ecf\u63d2\u5165\u7684\u5b57\u7b26\u4e32 word \u7684\u524d\u7f00\u4e4b\u4e00\u4e3a prefix&#xff0c;\u8fd4\u56de true&#xff1b;\u5426\u5219&#xff0c;\u8fd4\u56de false\u3002<\/li>\n<\/ul>\n<h4>\u793a\u4f8b<\/h4>\n<p>\u8f93\u5165&#xff1a;<br \/>\n<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;Trie&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;insert&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;search&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;search&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;startsWith&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;insert&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;search&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;apple&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;apple&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>\u8f93\u51fa&#xff1a;<br \/>\n<span class=\"token punctuation\">[<\/span><span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>\u89e3\u91ca&#xff1a;<br \/>\n<span class=\"token class-name\">Trie<\/span> trie <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">insert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;apple&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">search<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;apple&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>   <span class=\"token comment\">\/\/ \u8fd4\u56de True<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">search<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u8fd4\u56de False<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8fd4\u56de True<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">insert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\ntrie<span class=\"token punctuation\">.<\/span><span class=\"token function\">search<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;app&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>     <span class=\"token comment\">\/\/ \u8fd4\u56de True<\/span><\/p>\n<h4>\u63d0\u793a<\/h4>\n<ul>\n<li>1 &lt;&#061; word.length, prefix.length &lt;&#061; 2000<\/li>\n<li>word \u548c prefix \u4ec5\u7531\u5c0f\u5199\u82f1\u6587\u5b57\u6bcd\u7ec4\u6210<\/li>\n<li>insert\u3001search \u548c startsWith \u8c03\u7528\u6b21\u6570\u603b\u8ba1\u4e0d\u8d85\u8fc7 3 * 10^4 \u6b21<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e8c\u3001\u539f\u9898\u5206\u6790<\/h3>\n<p>\u672c\u9898\u8981\u6c42\u6211\u4eec\u5b9e\u73b0\u4e00\u4e2a\u652f\u6301\u4e09\u79cd\u57fa\u672c\u64cd\u4f5c\u7684\u6570\u636e\u7ed3\u6784&#xff1a;\u63d2\u5165\u5b57\u7b26\u4e32\u3001\u7cbe\u786e\u67e5\u627e\u5b57\u7b26\u4e32\u3001\u5224\u65ad\u662f\u5426\u5b58\u5728\u4ee5\u67d0\u524d\u7f00\u5f00\u5934\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4e4d\u770b\u4e4b\u4e0b&#xff0c;\u8fd9\u4f3c\u4e4e\u53ef\u4ee5\u7528\u54c8\u5e0c\u8868&#xff08;HashMap&#xff09;\u89e3\u51b3&#xff1a;\u63d2\u5165\u65f6\u5b58\u5165 key&#xff0c;\u67e5\u627e\u65f6\u76f4\u63a5\u5224\u65ad key \u662f\u5426\u5b58\u5728\u3002\u4f46\u8fd9\u79cd\u65b9\u6cd5\u65e0\u6cd5\u9ad8\u6548\u652f\u6301\u201c\u524d\u7f00\u5339\u914d\u201d\u64cd\u4f5c&#xff08;startsWith&#xff09;\u3002\u4f8b\u5982&#xff0c;\u82e5\u5df2\u63d2\u5165 &#034;apple&#034;\u3001&#034;application&#034;\u3001&#034;apply&#034;&#xff0c;\u5f53\u67e5\u8be2\u524d\u7f00 &#034;app&#034; \u65f6&#xff0c;\u54c8\u5e0c\u8868\u9700\u8981\u904d\u5386\u6240\u6709 key \u624d\u80fd\u5224\u65ad\u662f\u5426\u5b58\u5728\u5339\u914d\u9879&#xff0c;\u6548\u7387\u4f4e\u4e0b\u3002<\/p>\n<p>\u800c Trie&#xff08;\u524d\u7f00\u6811&#xff09; \u6b63\u662f\u4e3a\u89e3\u51b3\u6b64\u7c7b\u95ee\u9898\u800c\u751f\u7684\u6570\u636e\u7ed3\u6784\u3002\u5b83\u901a\u8fc7\u5171\u4eab\u516c\u5171\u524d\u7f00\u7684\u65b9\u5f0f\u7ec4\u7ec7\u5b57\u7b26\u4e32&#xff0c;\u4f7f\u5f97\u524d\u7f00\u5339\u914d\u53ef\u4ee5\u5728 O(L) \u65f6\u95f4\u5185\u5b8c\u6210&#xff08;L \u4e3a\u524d\u7f00\u957f\u5ea6&#xff09;&#xff0c;\u65e0\u9700\u904d\u5386\u6574\u4e2a\u6570\u636e\u96c6\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u7b54\u6848\u6784\u601d<\/h3>\n<h4>3.1 Trie \u7684\u6838\u5fc3\u601d\u60f3<\/h4>\n<p>Trie \u662f\u4e00\u68f5\u591a\u53c9\u6811&#xff0c;\u6bcf\u4e2a\u8282\u70b9\u4ee3\u8868\u4e00\u4e2a\u5b57\u7b26\u3002\u4ece\u6839\u8282\u70b9\u5230\u4efb\u610f\u8282\u70b9\u7684\u8def\u5f84\u6784\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u524d\u7f00\u3002\u5173\u952e\u7279\u6027\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>\u6839\u8282\u70b9\u4e0d\u5b58\u50a8\u5b57\u7b26&#xff0c;\u4ec5\u4f5c\u4e3a\u8d77\u70b9\u3002<\/li>\n<li>\u6bcf\u4e2a\u8282\u70b9\u5305\u542b\u82e5\u5e72\u5b50\u8282\u70b9&#xff0c;\u5bf9\u5e94\u53ef\u80fd\u7684\u4e0b\u4e00\u4e2a\u5b57\u7b26\u3002<\/li>\n<li>\u6807\u8bb0\u7ed3\u675f\u8282\u70b9&#xff1a;\u67d0\u4e9b\u8282\u70b9\u88ab\u6807\u8bb0\u4e3a\u201c\u5355\u8bcd\u7ed3\u5c3e\u201d&#xff0c;\u8868\u793a\u4ece\u6839\u5230\u8be5\u8282\u70b9\u7684\u8def\u5f84\u6784\u6210\u4e00\u4e2a\u5b8c\u6574\u5355\u8bcd\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u63d2\u5165 &#034;app&#034; \u548c &#034;apple&#034; \u540e\u7684 Trie \u7ed3\u6784\u5982\u4e0b&#xff08;\u7b80\u5316\u56fe\u793a&#xff09;&#xff1a;<\/p>\n<p>        (root)<br \/>\n          |<br \/>\n          a<br \/>\n          |<br \/>\n          p<br \/>\n          |<br \/>\n          p  \u2190 isEnd &#061; true &#xff08;&#034;app&#034;&#xff09;<br \/>\n          |<br \/>\n          l<br \/>\n          |<br \/>\n          e  \u2190 isEnd &#061; true &#xff08;&#034;apple&#034;&#xff09;<\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff0c;\u4e24\u4e2a\u5355\u8bcd\u5171\u4eab\u4e86\u524d\u7f00 &#034;app&#034;&#xff0c;\u8282\u7701\u4e86\u5b58\u50a8\u7a7a\u95f4&#xff0c;\u540c\u65f6\u652f\u6301\u9ad8\u6548\u7684\u524d\u7f00\u67e5\u8be2\u3002<\/p>\n<h4>3.2 \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1<\/h4>\n<p>\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a Trie \u7c7b&#xff0c;\u5305\u542b\u4ee5\u4e0b\u6210\u5458&#xff1a;<\/p>\n<ul>\n<li>children: \u957f\u5ea6\u4e3a 26 \u7684\u6570\u7ec4&#xff0c;children[i] \u8868\u793a\u5f53\u524d\u8282\u70b9\u7684\u7b2c i \u4e2a\u5b50\u8282\u70b9&#xff08;\u5bf9\u5e94 &#039;a&#039; &#043; i \u5b57\u7b26&#xff09;\u3002<\/li>\n<li>isEnd: \u5e03\u5c14\u503c&#xff0c;\u6807\u8bb0\u5f53\u524d\u8282\u70b9\u662f\u5426\u4e3a\u67d0\u4e2a\u5355\u8bcd\u7684\u7ed3\u5c3e\u3002<\/li>\n<\/ul>\n<p>\u4e3a\u4ec0\u4e48\u7528\u6570\u7ec4\u800c\u4e0d\u662f Map&#xff1f;<br \/>\n\u56e0\u4e3a\u9898\u76ee\u9650\u5b9a\u5b57\u7b26\u4ec5\u4e3a\u5c0f\u5199\u5b57\u6bcd&#xff08;\u5171 26 \u4e2a&#xff09;&#xff0c;\u4f7f\u7528\u56fa\u5b9a\u5927\u5c0f\u6570\u7ec4\u8bbf\u95ee\u66f4\u5feb&#xff08;O(1)&#xff09;&#xff0c;\u4e14\u5185\u5b58\u8fde\u7eed\u6027\u66f4\u597d\u3002\u82e5\u5b57\u7b26\u96c6\u66f4\u5927\u6216\u4e0d\u786e\u5b9a&#xff0c;\u53ef\u6539\u7528 HashMap&lt;Character, Trie&gt;\u3002<\/p>\n<h4>3.3 \u64cd\u4f5c\u903b\u8f91<\/h4>\n<h5>\u63d2\u5165&#xff08;insert&#xff09;<\/h5>\n<li>\u4ece\u6839\u8282\u70b9\u5f00\u59cb\u3002<\/li>\n<li>\u5bf9 word \u4e2d\u6bcf\u4e2a\u5b57\u7b26 ch&#xff1a;\n<ul>\n<li>\u8ba1\u7b97\u7d22\u5f15 index &#061; ch &#8211; &#039;a&#039;<\/li>\n<li>\u82e5 children[index] &#061;&#061; null&#xff0c;\u5219\u65b0\u5efa\u4e00\u4e2a\u5b50\u8282\u70b9<\/li>\n<li>\u79fb\u52a8\u5230\u8be5\u5b50\u8282\u70b9<\/li>\n<\/ul>\n<\/li>\n<li>\u6700\u540e\u5c06\u5f53\u524d\u8282\u70b9\u7684 isEnd \u8bbe\u4e3a true<\/li>\n<h5>\u67e5\u627e\u5b8c\u6574\u5355\u8bcd&#xff08;search&#xff09;<\/h5>\n<li>\u8c03\u7528\u8f85\u52a9\u65b9\u6cd5 searchPrefix(word) \u83b7\u53d6\u5bf9\u5e94\u8282\u70b9<\/li>\n<li>\u82e5\u8282\u70b9\u975e\u7a7a \u4e14 isEnd &#061;&#061; true&#xff0c;\u5219\u8fd4\u56de true<\/li>\n<h5>\u5224\u65ad\u524d\u7f00\u5b58\u5728&#xff08;startsWith&#xff09;<\/h5>\n<li>\u8c03\u7528 searchPrefix(prefix)<\/li>\n<li>\u82e5\u8fd4\u56de\u975e\u7a7a\u8282\u70b9&#xff0c;\u5219\u8bf4\u660e\u5b58\u5728\u8be5\u524d\u7f00<\/li>\n<h5>\u8f85\u52a9\u65b9\u6cd5&#xff1a;searchPrefix<\/h5>\n<ul>\n<li>\u4ece\u6839\u5f00\u59cb&#xff0c;\u9010\u5b57\u7b26\u5411\u4e0b\u904d\u5386<\/li>\n<li>\u82e5\u67d0\u5b57\u7b26\u5bf9\u5e94\u7684\u5b50\u8282\u70b9\u4e3a\u7a7a&#xff0c;\u8fd4\u56de null<\/li>\n<li>\u5426\u5219\u8fd4\u56de\u6700\u7ec8\u5230\u8fbe\u7684\u8282\u70b9<\/li>\n<\/ul>\n<hr \/>\n<h3>\u56db\u3001\u5b8c\u6574\u7b54\u6848&#xff08;Java \u5b9e\u73b0&#xff09;<\/h3>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Trie<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> children<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">boolean<\/span> isEnd<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u521d\u59cb\u5316 Trie \u6839\u8282\u70b9<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ 26 \u4e2a\u5c0f\u5199\u5b57\u6bcd<\/span><br \/>\n        children <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">26<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        isEnd <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u63d2\u5165\u4e00\u4e2a\u5355\u8bcd\u5230 Trie \u4e2d<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">insert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> word<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">Trie<\/span> node <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u4ece\u6839\u8282\u70b9\u5f00\u59cb<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> word<span class=\"token punctuation\">.<\/span><span class=\"token function\">length<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">char<\/span> ch <span class=\"token operator\">&#061;<\/span> word<span class=\"token punctuation\">.<\/span><span class=\"token function\">charAt<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> index <span class=\"token operator\">&#061;<\/span> ch <span class=\"token operator\">&#8211;<\/span> <span class=\"token char\">&#039;a&#039;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u8f6c\u6362\u4e3a 0~25 \u7684\u7d22\u5f15<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u5982\u679c\u8be5\u5b57\u7b26\u5bf9\u5e94\u7684\u5b50\u8282\u70b9\u4e0d\u5b58\u5728&#xff0c;\u521b\u5efa\u65b0\u8282\u70b9<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u79fb\u52a8\u5230\u5b50\u8282\u70b9<\/span><br \/>\n            node <span class=\"token operator\">&#061;<\/span> node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u6807\u8bb0\u5f53\u524d\u8282\u70b9\u4e3a\u5355\u8bcd\u7ed3\u5c3e<\/span><br \/>\n        node<span class=\"token punctuation\">.<\/span>isEnd <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u67e5\u627e\u5355\u8bcd\u662f\u5426\u5b58\u5728\u4e8e Trie \u4e2d&#xff08;\u5fc5\u987b\u662f\u5b8c\u6574\u5355\u8bcd&#xff09;<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">boolean<\/span> <span class=\"token function\">search<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> word<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">Trie<\/span> node <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">searchPrefix<\/span><span class=\"token punctuation\">(<\/span>word<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u8282\u70b9\u5b58\u5728 \u4e14 \u662f\u5355\u8bcd\u7ed3\u5c3e<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> node <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span> <span class=\"token operator\">&amp;&amp;<\/span> node<span class=\"token punctuation\">.<\/span>isEnd<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u5224\u65ad\u662f\u5426\u5b58\u5728\u4ee5 prefix \u5f00\u5934\u7684\u5355\u8bcd<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">boolean<\/span> <span class=\"token function\">startsWith<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> prefix<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/ \u53ea\u9700\u5224\u65ad\u524d\u7f00\u8def\u5f84\u662f\u5426\u5b58\u5728<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token function\">searchPrefix<\/span><span class=\"token punctuation\">(<\/span>prefix<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/**<br \/>\n     * \u8f85\u52a9\u65b9\u6cd5&#xff1a;\u67e5\u627e prefix \u5bf9\u5e94\u7684\u6700\u540e\u4e00\u4e2a\u8282\u70b9<br \/>\n     * &#064;return \u82e5\u5b58\u5728\u5219\u8fd4\u56de\u8282\u70b9&#xff0c;\u5426\u5219\u8fd4\u56de null<br \/>\n     *\/<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Trie<\/span> <span class=\"token function\">searchPrefix<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> prefix<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">Trie<\/span> node <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> i <span class=\"token operator\">&lt;<\/span> prefix<span class=\"token punctuation\">.<\/span><span class=\"token function\">length<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> i<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">char<\/span> ch <span class=\"token operator\">&#061;<\/span> prefix<span class=\"token punctuation\">.<\/span><span class=\"token function\">charAt<\/span><span class=\"token punctuation\">(<\/span>i<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> index <span class=\"token operator\">&#061;<\/span> ch <span class=\"token operator\">&#8211;<\/span> <span class=\"token char\">&#039;a&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>            <span class=\"token comment\">\/\/ \u8def\u5f84\u4e2d\u65ad&#xff0c;\u524d\u7f00\u4e0d\u5b58\u5728<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><\/p>\n<p>            node <span class=\"token operator\">&#061;<\/span> node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">[<\/span>index<span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> node<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u2705 \u8be5\u5b9e\u73b0\u5b8c\u5168\u7b26\u5408\u9898\u76ee\u8981\u6c42&#xff0c;\u53ef\u901a\u8fc7 LeetCode \u5168\u90e8\u6d4b\u8bd5\u7528\u4f8b\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4ee3\u7801\u5206\u6790<\/h3>\n<h4>5.1 \u7c7b\u7ed3\u6784<\/h4>\n<ul>\n<li>Trie \u7c7b\u65e2\u662f\u8282\u70b9\u7c7b\u578b&#xff0c;\u4e5f\u662f\u6574\u68f5\u6811\u7684\u5165\u53e3&#xff08;\u6839\u8282\u70b9&#xff09;\u3002<\/li>\n<li>\u6bcf\u4e2a Trie \u5b9e\u4f8b\u4ee3\u8868\u6811\u4e2d\u7684\u4e00\u4e2a\u8282\u70b9\u3002<\/li>\n<li>\u4f7f\u7528 this \u4f5c\u4e3a\u6839\u8282\u70b9\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u7b26\u5408\u9762\u5411\u5bf9\u8c61\u8bbe\u8ba1\u3002<\/li>\n<\/ul>\n<h4>5.2 \u5173\u952e\u65b9\u6cd5\u89e3\u6790<\/h4>\n<h5>insert<\/h5>\n<ul>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6&#xff1a;O(L)&#xff0c;L \u4e3a word \u957f\u5ea6<\/li>\n<li>\u6bcf\u6b21\u53ea\u5904\u7406\u4e00\u4e2a\u5b57\u7b26&#xff0c;\u6700\u591a\u521b\u5efa L \u4e2a\u65b0\u8282\u70b9<\/li>\n<li>\u6700\u540e\u8bbe\u7f6e isEnd &#061; true \u662f\u5173\u952e&#xff0c;\u533a\u5206\u201c\u524d\u7f00\u201d\u548c\u201c\u5b8c\u6574\u5355\u8bcd\u201d<\/li>\n<\/ul>\n<h5>search vs startsWith<\/h5>\n<ul>\n<li>\u4e24\u8005\u90fd\u4f9d\u8d56 searchPrefix<\/li>\n<li>\u533a\u522b\u5728\u4e8e&#xff1a;search \u8981\u6c42\u8282\u70b9\u662f\u5355\u8bcd\u7ed3\u5c3e&#xff0c;startsWith \u53ea\u8981\u6c42\u8def\u5f84\u5b58\u5728<\/li>\n<\/ul>\n<h5>searchPrefix<\/h5>\n<ul>\n<li>\u5c01\u88c5\u4e86\u516c\u5171\u903b\u8f91&#xff0c;\u907f\u514d\u4ee3\u7801\u91cd\u590d<\/li>\n<li>\u8fd4\u56de\u8282\u70b9\u800c\u975e\u5e03\u5c14\u503c&#xff0c;\u4fbf\u4e8e\u4e0a\u5c42\u5224\u65ad<\/li>\n<\/ul>\n<h4>5.3 \u8fb9\u754c\u60c5\u51b5\u5904\u7406<\/h4>\n<ul>\n<li>\u7a7a\u5b57\u7b26\u4e32&#xff1f;\u9898\u76ee\u89c4\u5b9a\u957f\u5ea6 \u22651&#xff0c;\u65e0\u9700\u5904\u7406<\/li>\n<li>\u91cd\u590d\u63d2\u5165&#xff1f;\u591a\u6b21\u63d2\u5165\u540c\u4e00\u5355\u8bcd&#xff0c;isEnd \u4ecd\u4e3a true&#xff0c;\u65e0\u526f\u4f5c\u7528<\/li>\n<li>\u67e5\u8be2\u4e0d\u5b58\u5728\u7684\u524d\u7f00&#xff1f;searchPrefix \u8fd4\u56de null&#xff0c;\u4e0a\u5c42\u5b89\u5168\u5904\u7406<\/li>\n<\/ul>\n<hr \/>\n<h3>\u516d\u3001\u65f6\u95f4\u590d\u6742\u5ea6\u4e0e\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790<\/h3>\n<h4>6.1 \u65f6\u95f4\u590d\u6742\u5ea6<\/h4>\n<table>\n<tr>\u64cd\u4f5c\u65f6\u95f4\u590d\u6742\u5ea6\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>Trie() \u521d\u59cb\u5316<\/td>\n<td>O(1)<\/td>\n<td>\u4ec5\u5206\u914d 26 \u4e2a\u5f15\u7528&#xff08;\u672a\u521b\u5efa\u5b50\u8282\u70b9&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>insert(word)<\/td>\n<td>O(L)<\/td>\n<td>L &#061; word.length()&#xff0c;\u6bcf\u4e2a\u5b57\u7b26\u5904\u7406\u4e00\u6b21<\/td>\n<\/tr>\n<tr>\n<td>search(word)<\/td>\n<td>O(L)<\/td>\n<td>\u540c\u4e0a<\/td>\n<\/tr>\n<tr>\n<td>startsWith(prefix)<\/td>\n<td>O(L)<\/td>\n<td>L &#061; prefix.length()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6240\u6709\u64cd\u4f5c\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u4ec5\u4e0e\u5b57\u7b26\u4e32\u957f\u5ea6\u76f8\u5173&#xff0c;\u4e0e\u5df2\u63d2\u5165\u5355\u8bcd\u603b\u6570\u65e0\u5173&#xff01;\u8fd9\u662f Trie \u76f8\u6bd4\u54c8\u5e0c\u8868\u7684\u6700\u5927\u4f18\u52bf\u3002<\/p>\n<h4>6.2 \u7a7a\u95f4\u590d\u6742\u5ea6<\/h4>\n<ul>\n<li>\n<p>\u6700\u574f\u60c5\u51b5&#xff1a;\u6240\u6709\u63d2\u5165\u7684\u5355\u8bcd\u65e0\u516c\u5171\u524d\u7f00&#xff08;\u5982 \u201ca\u201d, \u201cb\u201d, \u201cc\u201d, \u2026&#xff09;<\/p>\n<ul>\n<li>\u6bcf\u4e2a\u5355\u8bcd\u9700\u72ec\u7acb\u8def\u5f84<\/li>\n<li>\u603b\u8282\u70b9\u6570 \u2248 \u6240\u6709\u5355\u8bcd\u957f\u5ea6\u4e4b\u548c<\/li>\n<li>\u6bcf\u4e2a\u8282\u70b9\u5360\u7528 26 * \u5f15\u7528\u5927\u5c0f &#043; 1 * boolean<\/li>\n<li>\u7a7a\u95f4\u590d\u6742\u5ea6&#xff1a;O(N \u00d7 L \u00d7 \u03a3)&#xff0c;\u5176\u4e2d&#xff1a;\n<ul>\n<li>N&#xff1a;\u5355\u8bcd\u6570\u91cf<\/li>\n<li>L&#xff1a;\u5e73\u5747\u5355\u8bcd\u957f\u5ea6<\/li>\n<li>\u03a3&#xff1a;\u5b57\u7b26\u96c6\u5927\u5c0f&#xff08;\u672c\u9898 \u03a3&#061;26&#xff09;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6700\u597d\u60c5\u51b5&#xff1a;\u6240\u6709\u5355\u8bcd\u5171\u4eab\u957f\u524d\u7f00&#xff08;\u5982 \u201capp\u201d, \u201capple\u201d, \u201capplication\u201d&#xff09;<\/p>\n<ul>\n<li>\u8282\u70b9\u590d\u7528\u7387\u9ad8&#xff0c;\u7a7a\u95f4\u8282\u7701\u663e\u8457<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u82f1\u6587\u5355\u8bcd\u901a\u5e38\u6709\u5927\u91cf\u516c\u5171\u524d\u7f00&#xff0c;Trie \u7684\u7a7a\u95f4\u6548\u7387\u8f83\u9ad8\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u89e3\u7b54&#xff08;FAQ&#xff09;<\/h3>\n<h4>Q1: \u4e3a\u4ec0\u4e48\u4e0d\u7528 HashMap \u5b58\u50a8\u5b50\u8282\u70b9&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u672c\u9898\u5b57\u7b26\u96c6\u56fa\u5b9a&#xff08;26 \u5c0f\u5199\u5b57\u6bcd&#xff09;&#xff0c;\u6570\u7ec4\u8bbf\u95ee\u66f4\u5feb&#xff08;\u76f4\u63a5\u7d22\u5f15 vs \u54c8\u5e0c\u8ba1\u7b97&#xff09;&#xff0c;\u4e14\u5185\u5b58\u66f4\u7d27\u51d1\u3002\u82e5\u5b57\u7b26\u96c6\u5927&#xff08;\u5982 Unicode&#xff09;\u6216\u7a00\u758f&#xff0c;\u53ef\u7528 Map&lt;Character, Trie&gt; \u8282\u7701\u7a7a\u95f4\u3002<\/p>\n<h4>Q2: \u5982\u4f55\u5220\u9664\u4e00\u4e2a\u5355\u8bcd&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;LeetCode \u672c\u9898\u4e0d\u8981\u6c42&#xff0c;\u4f46\u53ef\u6269\u5c55&#xff1a;<\/p>\n<ul>\n<li>\u5148\u67e5\u627e\u5355\u8bcd\u662f\u5426\u5b58\u5728<\/li>\n<li>\u4ece\u5c3e\u90e8\u5411\u4e0a\u56de\u6eaf&#xff0c;\u82e5\u67d0\u8282\u70b9\u65e0\u5b50\u8282\u70b9\u4e14\u975e\u5176\u4ed6\u5355\u8bcd\u7ed3\u5c3e&#xff0c;\u53ef\u5220\u9664<\/li>\n<li>\u9700\u6ce8\u610f&#xff1a;\u4e0d\u80fd\u7834\u574f\u5176\u4ed6\u5171\u4eab\u524d\u7f00\u7684\u5355\u8bcd<\/li>\n<\/ul>\n<h4>Q3: Trie \u80fd\u5904\u7406\u4e2d\u6587\u5417&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u53ef\u4ee5&#xff0c;\u4f46\u9700\u8c03\u6574&#xff1a;<\/p>\n<ul>\n<li>\u5b57\u7b26\u96c6\u53d8\u5927&#xff08;\u5e38\u7528\u6c49\u5b57\u7ea6 3500&#043;&#xff09;<\/li>\n<li>\u6539\u7528 Map&lt;Character, Trie&gt; \u6216 Trie[] \u52a8\u6001\u6269\u5bb9<\/li>\n<li>\u5185\u5b58\u5f00\u9500\u663e\u8457\u589e\u52a0<\/li>\n<\/ul>\n<h4>Q4: isEnd \u7684\u4f5c\u7528\u662f\u4ec0\u4e48&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u533a\u5206\u201c\u8def\u5f84\u5b58\u5728\u201d\u548c\u201c\u5b8c\u6574\u5355\u8bcd\u201d\u3002\u4f8b\u5982&#xff1a;<\/p>\n<ul>\n<li>\u63d2\u5165 \u201capp\u201d \u540e&#xff0c;\u201ca\u201d\u3001\u201cap\u201d \u8def\u5f84\u5b58\u5728&#xff0c;\u4f46\u4e0d\u662f\u5355\u8bcd<\/li>\n<li>\u53ea\u6709 \u201capp\u201d \u7684\u672b\u8282\u70b9 isEnd &#061; true<\/li>\n<\/ul>\n<hr \/>\n<h3>\u516b\u3001\u4f18\u5316\u601d\u8def<\/h3>\n<h4>8.1 \u7a7a\u95f4\u4f18\u5316&#xff1a;\u4f7f\u7528 Map \u66ff\u4ee3\u6570\u7ec4<\/h4>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Trie<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token class-name\">Map<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">Character<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> children <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">HashMap<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">boolean<\/span> isEnd <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">false<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">insert<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span> word<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">Trie<\/span> node <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">this<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">for<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token keyword\">char<\/span> ch <span class=\"token operator\">:<\/span> word<span class=\"token punctuation\">.<\/span><span class=\"token function\">toCharArray<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">.<\/span><span class=\"token function\">putIfAbsent<\/span><span class=\"token punctuation\">(<\/span>ch<span class=\"token punctuation\">,<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Trie<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            node <span class=\"token operator\">&#061;<\/span> node<span class=\"token punctuation\">.<\/span>children<span class=\"token punctuation\">.<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span>ch<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        node<span class=\"token punctuation\">.<\/span>isEnd <span class=\"token operator\">&#061;<\/span> <span class=\"token boolean\">true<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\">\/\/ \u5176\u4ed6\u65b9\u6cd5\u7c7b\u4f3c&#8230;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4f18\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u8282\u7701\u5185\u5b58&#xff08;\u5c24\u5176\u5b57\u7b26\u96c6\u5927\u6216\u7a00\u758f\u65f6&#xff09;<\/li>\n<li>\u652f\u6301\u4efb\u610f\u5b57\u7b26<\/li>\n<\/ul>\n<p>\u7f3a\u70b9&#xff1a;<\/p>\n<ul>\n<li>\u54c8\u5e0c\u8ba1\u7b97\u5f00\u9500<\/li>\n<li>\u65e0\u6cd5\u5229\u7528\u5b57\u7b26\u8fde\u7eed\u6027<\/li>\n<\/ul>\n<h4>8.2 \u538b\u7f29 Trie&#xff08;Radix Tree \/ Patricia Trie&#xff09;<\/h4>\n<p>\u5c06\u5355\u94fe\u8def\u5f84\u538b\u7f29\u4e3a\u4e00\u4e2a\u8282\u70b9&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>\u539f\u59cb: a -&gt; p -&gt; p -&gt; l -&gt; e<br \/>\n\u538b\u7f29: &#034;apple&#034;<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff1a;\u957f\u5355\u8bcd\u3001\u4f4e\u5206\u652f\u5ea6&#xff08;\u5982 IP \u8def\u7531\u8868&#xff09;<\/p>\n<h4>8.3 \u6dfb\u52a0\u8ba1\u6570\u529f\u80fd<\/h4>\n<p>\u5728\u8282\u70b9\u4e2d\u589e\u52a0 int count&#xff0c;\u8bb0\u5f55\u4ee5\u8be5\u8282\u70b9\u4e3a\u524d\u7f00\u7684\u5355\u8bcd\u6570\u91cf&#xff0c;\u652f\u6301&#xff1a;<\/p>\n<ul>\n<li>\u7edf\u8ba1\u524d\u7f00\u51fa\u73b0\u6b21\u6570<\/li>\n<li>\u5b9e\u73b0 Top-K \u81ea\u52a8\u8865\u5168<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e5d\u3001\u6570\u636e\u7ed3\u6784\u4e0e\u7b97\u6cd5\u57fa\u7840\u77e5\u8bc6\u70b9\u56de\u987e<\/h3>\n<h4>9.1 \u4ec0\u4e48\u662f Trie&#xff08;\u524d\u7f00\u6811&#xff09;&#xff1f;<\/h4>\n<ul>\n<li>\u5b9a\u4e49&#xff1a;\u4e00\u79cd\u6709\u5e8f\u6811&#xff0c;\u7528\u4e8e\u5b58\u50a8\u52a8\u6001\u96c6\u5408&#xff0c;\u5176\u4e2d\u952e\u901a\u5e38\u662f\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u522b\u540d&#xff1a;\u5b57\u5178\u6811\u3001\u5355\u8bcd\u67e5\u627e\u6811<\/li>\n<li>\u6838\u5fc3\u601d\u60f3&#xff1a;\u7a7a\u95f4\u6362\u65f6\u95f4&#xff0c;\u901a\u8fc7\u5171\u4eab\u524d\u7f00\u52a0\u901f\u67e5\u8be2<\/li>\n<\/ul>\n<h4>9.2 Trie \u7684\u5178\u578b\u6027\u8d28<\/h4>\n<table>\n<tr>\u6027\u8d28\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>\u6839\u8282\u70b9<\/td>\n<td>\u4e0d\u5305\u542b\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\u8def\u5f84<\/td>\n<td>\u4ece\u6839\u5230\u8282\u70b9\u7684\u8def\u5f84 &#061; \u5b57\u7b26\u4e32\u524d\u7f00<\/td>\n<\/tr>\n<tr>\n<td>\u5206\u652f<\/td>\n<td>\u6bcf\u4e2a\u8282\u70b9\u7684\u5b50\u8282\u70b9\u4ee3\u8868\u4e0d\u540c\u5b57\u7b26<\/td>\n<\/tr>\n<tr>\n<td>\u53f6\u5b50<\/td>\n<td>\u4e0d\u4e00\u5b9a\u662f\u5355\u8bcd\u7ed3\u5c3e&#xff08;\u56e0\u5355\u8bcd\u53ef\u4e3a\u53e6\u4e00\u5355\u8bcd\u524d\u7f00&#xff09;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>9.3 \u4e0e\u5176\u4ed6\u6570\u636e\u7ed3\u6784\u5bf9\u6bd4<\/h4>\n<table>\n<tr>\u6570\u636e\u7ed3\u6784\u63d2\u5165\u67e5\u627e\u524d\u7f00\u5339\u914d\u7a7a\u95f4<\/tr>\n<tbody>\n<tr>\n<td>HashSet<\/td>\n<td>O(1)<\/td>\n<td>O(1)<\/td>\n<td>O(N\u00d7L)<\/td>\n<td>\u4f4e<\/td>\n<\/tr>\n<tr>\n<td>TreeSet<\/td>\n<td>O(L log N)<\/td>\n<td>O(L log N)<\/td>\n<td>O(L &#043; K)<\/td>\n<td>\u4e2d<\/td>\n<\/tr>\n<tr>\n<td>Trie<\/td>\n<td>O(L)<\/td>\n<td>O(L)<\/td>\n<td>O(L)<\/td>\n<td>\u9ad8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8&#xff1a;TreeSet \u7684\u524d\u7f00\u5339\u914d\u9700\u4e2d\u5e8f\u904d\u5386&#xff0c;K \u4e3a\u5339\u914d\u7ed3\u679c\u6570<\/p>\n<h4>9.4 Trie \u7684\u5c40\u9650\u6027<\/h4>\n<ul>\n<li>\u5185\u5b58\u6d88\u8017\u5927&#xff1a;\u6bcf\u4e2a\u8282\u70b9\u9700\u5b58\u50a8 \u03a3 \u4e2a\u6307\u9488<\/li>\n<li>\u7f13\u5b58\u4e0d\u53cb\u597d&#xff1a;\u8282\u70b9\u5206\u6563&#xff0c;\u7f13\u5b58\u547d\u4e2d\u7387\u4f4e<\/li>\n<li>\u4e0d\u9002\u5408\u77ed\u5355\u8bcd\u96c6&#xff1a;\u82e5\u5355\u8bcd\u5c11\u4e14\u65e0\u516c\u5171\u524d\u7f00&#xff0c;\u4e0d\u5982\u54c8\u5e0c\u8868<\/li>\n<\/ul>\n<hr \/>\n<h3>\u5341\u3001\u9762\u8bd5\u5b98\u63d0\u95ee\u73af\u8282&#xff08;\u6a21\u62df&#xff09;<\/h3>\n<h4>Q1: \u4f60\u80fd\u624b\u5199\u4e00\u4e2a Trie \u5417&#xff1f;\u91cd\u70b9\u8bb2\u8bb2 search \u548c startsWith \u7684\u533a\u522b\u3002<\/h4>\n<p>\u7b54&#xff1a;\u5f53\u7136\u3002\u4e24\u8005\u90fd\u8c03\u7528 searchPrefix \u627e\u5230\u524d\u7f00\u672b\u5c3e\u8282\u70b9\u3002\u533a\u522b\u5728\u4e8e&#xff1a;<\/p>\n<ul>\n<li>search \u8981\u6c42\u8be5\u8282\u70b9 isEnd &#061;&#061; true&#xff0c;\u5373\u662f\u4e00\u4e2a\u5b8c\u6574\u63d2\u5165\u7684\u5355\u8bcd<\/li>\n<li>startsWith \u53ea\u8981\u8def\u5f84\u5b58\u5728\u5373\u53ef&#xff0c;\u4e0d\u8981\u6c42\u662f\u5b8c\u6574\u5355\u8bcd<\/li>\n<\/ul>\n<p>\u4f8b\u5982&#xff0c;\u63d2\u5165 \u201capple\u201d \u540e&#xff1a;<\/p>\n<ul>\n<li>search(&#034;app&#034;) \u2192 false&#xff08;\u201capp\u201d \u672a\u88ab\u63d2\u5165&#xff09;<\/li>\n<li>startsWith(&#034;app&#034;) \u2192 true&#xff08;\u201capple\u201d \u4ee5 \u201capp\u201d \u5f00\u5934&#xff09;<\/li>\n<\/ul>\n<h4>Q2: \u5982\u679c\u5b57\u7b26\u96c6\u5305\u542b\u5927\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u7b26\u53f7&#xff0c;\u5982\u4f55\u4fee\u6539&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u6709\u51e0\u79cd\u65b9\u6848&#xff1a;<\/p>\n<li>\u6269\u5927\u6570\u7ec4&#xff1a;\u5982 ASCII 128 \u5b57\u7b26 \u2192 new Trie[128]&#xff0c;\u7d22\u5f15 ch<\/li>\n<li>\u4f7f\u7528 Map&#xff1a;Map&lt;Character, Trie&gt; children&#xff0c;\u901a\u7528\u6027\u5f3a<\/li>\n<li>\u54c8\u5e0c\u6620\u5c04&#xff1a;\u81ea\u5b9a\u4e49\u5b57\u7b26\u5230\u7d22\u5f15\u7684\u6620\u5c04\u51fd\u6570<\/li>\n<p>\u63a8\u8350\u65b9\u6848 2&#xff0c;\u7075\u6d3b\u4e14\u8282\u7701\u7a7a\u95f4\u3002<\/p>\n<h4>Q3: Trie \u5728\u641c\u7d22\u5f15\u64ce\u4e2d\u5982\u4f55\u7528\u4e8e\u81ea\u52a8\u8865\u5168&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<li>\u7528\u6237\u8f93\u5165\u524d\u7f00&#xff08;\u5982 \u201cjav\u201d&#xff09;<\/li>\n<li>\u5728 Trie \u4e2d\u67e5\u627e\u8be5\u524d\u7f00\u5bf9\u5e94\u8282\u70b9<\/li>\n<li>\u4ece\u8be5\u8282\u70b9 DFS \u904d\u5386\u6240\u6709\u5b50\u6811&#xff0c;\u6536\u96c6 isEnd &#061;&#061; true \u7684\u5b8c\u6574\u5355\u8bcd<\/li>\n<li>\u6309\u70ed\u5ea6\/\u9891\u7387\u6392\u5e8f\u540e\u8fd4\u56de Top-K \u5efa\u8bae<\/li>\n<p>\u53ef\u8fdb\u4e00\u6b65\u4f18\u5316&#xff1a;<\/p>\n<ul>\n<li>\u8282\u70b9\u5b58\u50a8\u70ed\u95e8\u8bcd\u8ba1\u6570<\/li>\n<li>\u4f7f\u7528\u4f18\u5148\u961f\u5217\u9650\u5236\u7ed3\u679c\u6570\u91cf<\/li>\n<\/ul>\n<h4>Q4: \u5982\u4f55\u7edf\u8ba1\u4ee5\u67d0\u524d\u7f00\u5f00\u5934\u7684\u5355\u8bcd\u6570\u91cf&#xff1f;<\/h4>\n<p>\u7b54&#xff1a;\u53ef\u5728\u8282\u70b9\u4e2d\u589e\u52a0 int prefixCount \u5b57\u6bb5&#xff1a;<\/p>\n<ul>\n<li>insert \u65f6&#xff0c;\u8def\u5f84\u4e0a\u6bcf\u4e2a\u8282\u70b9 prefixCount&#043;&#043;<\/li>\n<li>\u67e5\u8be2\u65f6\u76f4\u63a5\u8fd4\u56de\u8be5\u8282\u70b9\u7684 prefixCount<\/li>\n<\/ul>\n<p>\u4f8b\u5982\u63d2\u5165 \u201capp\u201d, \u201capple\u201d&#xff1a;<\/p>\n<ul>\n<li>\u2018a\u2019 \u8282\u70b9 count&#061;2<\/li>\n<li>\u2018p\u2019 \u8282\u70b9 count&#061;2<\/li>\n<li>\u7b2c\u4e8c\u4e2a \u2018p\u2019 \u8282\u70b9 count&#061;2<\/li>\n<li>\u2018l\u2019 \u8282\u70b9 count&#061;1<\/li>\n<\/ul>\n<hr \/>\n<h3>\u5341\u4e00\u3001\u8fd9\u9053\u7b97\u6cd5\u9898\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u5e94\u7528<\/h3>\n<h4>11.1 \u641c\u7d22\u5f15\u64ce\u81ea\u52a8\u8865\u5168&#xff08;Autocomplete&#xff09;<\/h4>\n<ul>\n<li>\u7528\u6237\u8f93\u5165\u65f6\u5b9e\u65f6\u63d0\u793a\u53ef\u80fd\u7684\u641c\u7d22\u8bcd<\/li>\n<li>Trie \u652f\u6301\u6beb\u79d2\u7ea7\u524d\u7f00\u5339\u914d<\/li>\n<li>\u7ed3\u5408\u7528\u6237\u5386\u53f2\u3001\u70ed\u95e8\u8bcd\u63d0\u5347\u4f53\u9a8c<\/li>\n<\/ul>\n<h4>11.2 \u62fc\u5199\u68c0\u67e5&#xff08;Spell Checker&#xff09;<\/h4>\n<ul>\n<li>\u6784\u5efa\u6b63\u786e\u5355\u8bcd\u7684 Trie<\/li>\n<li>\u5bf9\u8f93\u5165\u5355\u8bcd&#xff0c;\u67e5\u627e\u7f16\u8f91\u8ddd\u79bb \u22641 \u7684\u5019\u9009\u8bcd&#xff08;\u9700\u7ed3\u5408\u5176\u4ed6\u7b97\u6cd5&#xff09;<\/li>\n<\/ul>\n<h4>11.3 IP \u8def\u7531\u8868&#xff08;Longest Prefix Match&#xff09;<\/h4>\n<ul>\n<li>\u5c06 IP \u5730\u5740\u89c6\u4e3a\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32<\/li>\n<li>\u4f7f\u7528\u538b\u7f29 Trie&#xff08;Patricia Trie&#xff09;\u9ad8\u6548\u5339\u914d\u6700\u957f\u524d\u7f00\u8def\u7531<\/li>\n<\/ul>\n<h4>11.4 \u654f\u611f\u8bcd\u8fc7\u6ee4<\/h4>\n<ul>\n<li>\u5c06\u654f\u611f\u8bcd\u5e93\u6784\u5efa\u6210 Trie<\/li>\n<li>\u5bf9\u6587\u672c\u9010\u5b57\u7b26\u5339\u914d&#xff0c;\u53d1\u73b0\u524d\u7f00\u5373\u89e6\u53d1\u8fc7\u6ee4<\/li>\n<\/ul>\n<h4>11.5 \u751f\u7269\u4fe1\u606f\u5b66&#xff1a;DNA \u5e8f\u5217\u5339\u914d<\/h4>\n<ul>\n<li>DNA \u5e8f\u5217\u7531 A\/T\/C\/G \u7ec4\u6210&#xff08;\u03a3&#061;4&#xff09;<\/li>\n<li>Trie \u7528\u4e8e\u5feb\u901f\u67e5\u627e\u57fa\u56e0\u7247\u6bb5<\/li>\n<\/ul>\n<hr \/>\n<h3>\u5341\u4e8c\u3001\u76f8\u5173\u9898\u76ee\u63a8\u8350<\/h3>\n<table>\n<tr>\u9898\u53f7\u9898\u76ee\u96be\u5ea6\u5173\u8054\u70b9<\/tr>\n<tbody>\n<tr>\n<td>211<\/td>\n<td>\u6dfb\u52a0\u4e0e\u641c\u7d22\u5355\u8bcd &#8211; \u6570\u636e\u7ed3\u6784\u8bbe\u8ba1<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>Trie &#043; \u901a\u914d\u7b26 \u2018.\u2019<\/td>\n<\/tr>\n<tr>\n<td>212<\/td>\n<td>\u5355\u8bcd\u641c\u7d22 II<\/td>\n<td>\u56f0\u96be<\/td>\n<td>Trie &#043; DFS \u7f51\u683c\u641c\u7d22<\/td>\n<\/tr>\n<tr>\n<td>421<\/td>\n<td>\u6570\u7ec4\u4e2d\u4e24\u4e2a\u6570\u7684\u6700\u5927\u5f02\u6216\u503c<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>\u4e8c\u8fdb\u5236 Trie<\/td>\n<\/tr>\n<tr>\n<td>648<\/td>\n<td>\u5355\u8bcd\u66ff\u6362<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>Trie \u524d\u7f00\u5339\u914d\u66ff\u6362<\/td>\n<\/tr>\n<tr>\n<td>677<\/td>\n<td>\u952e\u503c\u6620\u5c04<\/td>\n<td>\u4e2d\u7b49<\/td>\n<td>Trie &#043; \u8ba1\u6570<\/td>\n<\/tr>\n<tr>\n<td>720<\/td>\n<td>\u8bcd\u5178\u4e2d\u6700\u957f\u7684\u5355\u8bcd<\/td>\n<td>\u7b80\u5355<\/td>\n<td>Trie &#043; \u6392\u5e8f<\/td>\n<\/tr>\n<tr>\n<td>745<\/td>\n<td>\u524d\u7f00\u548c\u540e\u7f00\u641c\u7d22<\/td>\n<td>\u56f0\u96be<\/td>\n<td>\u53cc Trie \u6216\u540e\u7f00 Trie<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5efa\u8bae\u5b66\u4e60\u8def\u5f84&#xff1a;\u5148\u638c\u63e1\u672c\u9898 \u2192 211&#xff08;\u901a\u914d\u7b26&#xff09;\u2192 212&#xff08;\u7efc\u5408\u5e94\u7528&#xff09;\u2192 421&#xff08;\u4e8c\u8fdb\u5236 Trie&#xff09;<\/p>\n<hr \/>\n<h3>\u5341\u4e09\u3001\u603b\u7ed3\u4e0e\u5ef6\u4f38<\/h3>\n<h4>13.1 \u6838\u5fc3\u6536\u83b7<\/h4>\n<ul>\n<li>Trie \u662f\u5904\u7406\u5b57\u7b26\u4e32\u524d\u7f00\u95ee\u9898\u7684\u5229\u5668<\/li>\n<li>\u65f6\u95f4\u590d\u6742\u5ea6\u7a33\u5b9a O(L)&#xff0c;\u4e0d\u53d7\u6570\u636e\u89c4\u6a21\u5f71\u54cd<\/li>\n<li>\u8bbe\u8ba1\u5173\u952e&#xff1a;\u8282\u70b9\u7ed3\u6784&#xff08;children &#043; isEnd&#xff09;\u3001\u8def\u5f84\u904d\u5386\u903b\u8f91<\/li>\n<li>\u6743\u8861&#xff1a;\u7a7a\u95f4\u6362\u65f6\u95f4&#xff0c;\u9002\u7528\u4e8e\u524d\u7f00\u5bc6\u96c6\u573a\u666f<\/li>\n<\/ul>\n<h4>13.2 \u5ef6\u4f38\u601d\u8003<\/h4>\n<ul>\n<li>\u6301\u4e45\u5316 Trie&#xff1a;\u5982\u4f55\u5c06 Trie \u5b58\u5165\u6570\u636e\u5e93&#xff1f;<\/li>\n<li>\u5e76\u53d1\u5b89\u5168&#xff1a;\u591a\u7ebf\u7a0b\u63d2\u5165\/\u67e5\u8be2\u5982\u4f55\u52a0\u9501&#xff1f;&#xff08;\u8bfb\u5199\u9501 or \u65e0\u9501 Trie&#xff09;<\/li>\n<li>\u5206\u5e03\u5f0f Trie&#xff1a;\u6d77\u91cf\u8bcd\u5e93\u5982\u4f55\u5206\u7247\u5b58\u50a8&#xff1f;<\/li>\n<li>\u4e0e AC \u81ea\u52a8\u673a\u7ed3\u5408&#xff1a;\u591a\u6a21\u5f0f\u4e32\u5339\u914d&#xff08;\u5982\u654f\u611f\u8bcd\u68c0\u6d4b&#xff09;<\/li>\n<\/ul>\n<h4>13.3 \u5b66\u4e60\u5efa\u8bae<\/h4>\n<li>\u52a8\u624b\u5b9e\u73b0&#xff1a;\u624b\u5199 Trie \u662f\u9762\u8bd5\u9ad8\u9891\u9898<\/li>\n<li>\u7406\u89e3\u53d8\u79cd&#xff1a;\u538b\u7f29 Trie\u3001\u540e\u7f00 Trie\u3001\u4e8c\u8fdb\u5236 Trie<\/li>\n<li>\u8054\u7cfb\u5b9e\u9645&#xff1a;\u601d\u8003\u4f60\u5728\u9879\u76ee\u4e2d\u80fd\u5426\u7528 Trie \u4f18\u5316\u67d0\u529f\u80fd<\/li>\n<li>\u5237\u76f8\u5173\u9898&#xff1a;\u5de9\u56fa Trie \u5728\u4e0d\u540c\u573a\u666f\u7684\u5e94\u7528<\/li>\n<hr \/>\n<p>\u7ed3\u8bed&#xff1a;Trie \u867d\u7136\u4e0d\u662f\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784&#xff0c;\u4f46\u5728\u7279\u5b9a\u573a\u666f\u4e0b&#xff08;\u5c24\u5176\u662f\u6d89\u53ca\u524d\u7f00\u64cd\u4f5c\u65f6&#xff09;\u5177\u6709\u4e0d\u53ef\u66ff\u4ee3\u7684\u4f18\u52bf\u3002\u638c\u63e1\u5b83&#xff0c;\u4e0d\u4ec5\u662f\u4e3a\u4e86\u901a\u8fc7\u4e00\u9053 LeetCode \u9898&#xff0c;\u66f4\u662f\u4e3a\u4e86\u5728\u771f\u5b9e\u5de5\u7a0b\u4e2d\u591a\u4e00\u628a\u201c\u5229\u5668\u201d\u3002\u5e0c\u671b\u672c\u6587\u80fd\u52a9\u4f60\u6df1\u5165\u7406\u89e3 Trie \u7684\u7cbe\u9ad3&#xff0c;\u4ece\u5bb9\u5e94\u5bf9\u9762\u8bd5\u4e0e\u5b9e\u6218&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;&#xff1a;\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790\u6458\u8981&#xff1a;\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790 LeetCode \u70ed\u9898 100 \u4e2d\u7684\u7ecf\u5178\u9898\u76ee\u2014\u2014\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;\u3002\u6211\u4eec\u5c06\u4ece\u539f\u9898\u51fa\u53d1&#xff0c;\u9010\u6b65\u62c6\u89e3\u5176\u80cc\u540e\u7684\u7b97\u6cd5\u601d\u60f3\u3001\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1&#xff0c;\u5e76\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684 Java \u5b9e\u73b0\u4ee3\u7801\u3002\u6587\u7ae0\u6db5\u76d6\u65f6\u95f4\/\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u3001\u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3001\u76f8\u5173\u9898\u76ee\u63a8\u8350\u7b49\u6a21\u5757&amp;#xff0<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,2692,427],"topic":[],"class_list":["post-62142","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-leetcode","tag-427"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/62142.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;&#xff1a;\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790\u6458\u8981&#xff1a;\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790 LeetCode \u70ed\u9898 100 \u4e2d\u7684\u7ecf\u5178\u9898\u76ee\u2014\u2014\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;\u3002\u6211\u4eec\u5c06\u4ece\u539f\u9898\u51fa\u53d1&#xff0c;\u9010\u6b65\u62c6\u89e3\u5176\u80cc\u540e\u7684\u7b97\u6cd5\u601d\u60f3\u3001\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1&#xff0c;\u5e76\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684 Java \u5b9e\u73b0\u4ee3\u7801\u3002\u6587\u7ae0\u6db5\u76d6\u65f6\u95f4\/\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u3001\u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3001\u76f8\u5173\u9898\u76ee\u63a8\u8350\u7b49\u6a21\u5757&amp;#xff0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/62142.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-19T04:18:12+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62142.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/62142.html\",\"name\":\"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-19T04:18:12+00:00\",\"dateModified\":\"2026-01-19T04:18:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/62142.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/62142.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/62142.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/62142.html","og_locale":"zh_CN","og_type":"article","og_title":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;&#xff1a;\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790\u6458\u8981&#xff1a;\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790 LeetCode \u70ed\u9898 100 \u4e2d\u7684\u7ecf\u5178\u9898\u76ee\u2014\u2014\u5b9e\u73b0 Trie&#xff08;\u524d\u7f00\u6811&#xff09;\u3002\u6211\u4eec\u5c06\u4ece\u539f\u9898\u51fa\u53d1&#xff0c;\u9010\u6b65\u62c6\u89e3\u5176\u80cc\u540e\u7684\u7b97\u6cd5\u601d\u60f3\u3001\u6570\u636e\u7ed3\u6784\u8bbe\u8ba1&#xff0c;\u5e76\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684 Java \u5b9e\u73b0\u4ee3\u7801\u3002\u6587\u7ae0\u6db5\u76d6\u65f6\u95f4\/\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u3001\u5e38\u89c1\u9762\u8bd5\u95ee\u9898\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f\u3001\u76f8\u5173\u9898\u76ee\u63a8\u8350\u7b49\u6a21\u5757&amp;#xff0","og_url":"https:\/\/www.wsisp.com\/helps\/62142.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-19T04:18:12+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/62142.html","url":"https:\/\/www.wsisp.com\/helps\/62142.html","name":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-19T04:18:12+00:00","dateModified":"2026-01-19T04:18:12+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/62142.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/62142.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/62142.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Java\u7248LeetCode\u70ed\u9898100\u4e4b\u5b9e\u73b0 Trie\uff08\u524d\u7f00\u6811\uff09\uff1a\u4ece\u539f\u7406\u5230\u5b9e\u6218\u7684\u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62142","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=62142"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/62142\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=62142"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=62142"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=62142"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=62142"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}