Ruby's Louvre

每天学习一点点算法

导航

上一页 1 2 3 4 5 6 ··· 125 下一页

2020年1月3日 #

leetcode 977. Squares of a Sorted Array

摘要: 比较直观的解法 另一个,从左右两端开始比较,可能是 123与124比较,然后是 123与122 阅读全文

posted @ 2020-01-03 00:36 司徒正美 阅读(539) 评论(0) 推荐(0) 编辑

2020年1月2日 #

leetcode 844. Backspace String Compare

摘要: 比较两个带退格键的字符串 方法1, 从后往前遍历,记录要忽略掉的字符 方法2, 使用栈,从前往后处理 阅读全文

posted @ 2020-01-02 01:00 司徒正美 阅读(461) 评论(0) 推荐(0) 编辑

2019年12月31日 #

leetcode 1032. Stream of Characters

摘要: 用字典树即可解决。首先在init的时候,把words中所有word逆置后存入字典树中;在query的时候,也有逆序的方式记录所有历史query过的值,同时判断其前缀是否存在于字典树中即可。 阅读全文

posted @ 2019-12-31 14:57 司徒正美 阅读(489) 评论(0) 推荐(0) 编辑

leetcode 1023. Camelcase Matching

摘要: 使用前缀树, 多个字符串匹配一个模式 javascript function Node() { this.children = {} } class Trie { constructor() { this.root = new Node() } insert(word) { var node = t 阅读全文

posted @ 2019-12-31 02:32 司徒正美 阅读(465) 评论(0) 推荐(0) 编辑

2019年12月29日 #

leetcode 745 Prefix and Suffix Search

摘要: ```javascript var WordFilter = function (words) { this.trie = {}, idx = 0; for (let word of words) { let m = word.length; let paths = []; for (let i = 阅读全文

posted @ 2019-12-29 22:45 司徒正美 阅读(462) 评论(0) 推荐(0) 编辑

2019年12月28日 #

leetcode 720. Longest Word in Dictionary

摘要: 使用前缀树 javascript function Node() { this.word = '' this.children = {} } class Trie { constructor() { this.root = new Node() } addWord(word) { var node 阅读全文

posted @ 2019-12-28 22:35 司徒正美 阅读(460) 评论(0) 推荐(0) 编辑

leetcode 692. Top K Frequent Words

摘要: ```javascript function Node() { this.endCount = 0 this.word = '' this.children = {} } class Tire { constructor() { this.root = new Node() } addWord... 阅读全文

posted @ 2019-12-28 22:01 司徒正美 阅读(518) 评论(0) 推荐(0) 编辑

leetcode 677. Map Sum Pairs

摘要: 使用前缀树 或者 使用map优化一下 阅读全文

posted @ 2019-12-28 20:12 司徒正美 阅读(389) 评论(0) 推荐(0) 编辑

leetcode 676. Implement Magic Dictionary

摘要: 使用Tire 处理 javascript function Node(value) { this.word = null this.children = {} } class MagicDictionary { constructor() { this.root = new Node(null) } 阅读全文

posted @ 2019-12-28 00:17 司徒正美 阅读(374) 评论(0) 推荐(0) 编辑

2019年12月27日 #

leetcode 648. Replace Words

摘要: 将单词替换成其词根 阅读全文

posted @ 2019-12-27 21:43 司徒正美 阅读(454) 评论(0) 推荐(0) 编辑

上一页 1 2 3 4 5 6 ··· 125 下一页