Trie 树
实战题目
- 实现 Trie (前缀树) (亚马逊、微软、谷歌在半年内面试中考过)
- 单词搜索 II (亚马逊、微软、苹果在半年内面试中考过)
[ ] 分析单词搜索 2 用 Tire 树方式实现的时间复杂度,请同学们提交在学习总结中。
并查集模板
// JavaScriptclass unionFind {constructor(n) {this.count = n;this.parent = new Array(n);for (let i = 0; i < n; i++) {this.parent[i] = i;}}find(p) {let root = p;while (parent[root] !== root) {root = parent[root];}// 压缩路径while (parent[p] !== p) {let x = p;p = this.parent[p];this.parent[x] = root;}return root;}union(p, q) {let rootP = find(p);let rootQ = find(q);if (rootP === rootQ) return;this.parent[rootP] = rootQ;this.count--;}}
参考链接
-
实战题目
[ ] 朋友圈(亚马逊、Facebook、字节跳动在半年内面试中考过)
- 岛屿数量(近半年内,亚马逊在面试中考查此题达到 361 次)
- 被围绕的区域(亚马逊、eBay、谷歌在半年内面试中考过)
