博客园 - 司徒正美uuid:6cbd1ba2-f883-4c34-aed1-30dde64a3a3e;id=7076552020-02-27T18:27:28Z司徒正美https://www.cnblogs.com/rubylouvre/feed.cnblogs.comhttps://www.cnblogs.com/rubylouvre/p/12210814.htmlleetcode 91. Decode Ways - 司徒正美```javascript function numDecodings(s) { if (!s.length || s.charAt(0) === '0') { return 0 } var dp = new Array(s.length + 1).fill(0) dp[0] = 1; for (v2020-01-18T16:18:00Z2020-01-18T16:18:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript function numDecodings(s) { if (!s.length || s.charAt(0) === '0') { return 0 } var dp = new Array(s.length + 1).fill(0) dp[0] = 1; for (v <a href="https://www.cnblogs.com/rubylouvre/p/12210814.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12203480.htmlleetcode 1214 Two Sum BSTs - 司徒正美```javascript
function rob(a, b, target) { var hash = {} var stack = [a] while (queue.length) { var node = stack.pop() stack[target - node.val] = 1; if (node.left) ...2020-01-16T14:00:00Z2020-01-16T14:00:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript
function rob(a, b, target) { var hash = {} var stack = [a] while (queue.length) { var node = stack.pop() stack[target - node.val] = 1; if (node.left) ... <a href="https://www.cnblogs.com/rubylouvre/p/12203480.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12194578.htmlleetcode 213 House Robber II - 司徒正美你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金。这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的。同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报2020-01-14T15:16:00Z2020-01-14T15:16:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金。这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的。同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报 <a href="https://www.cnblogs.com/rubylouvre/p/12194578.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12191387.htmlleetcode 198 House Robber I - 司徒正美```javascript function rob(nums) { if(!nums || nums.length === 0) { return 0; } else if(nums.length2020-01-14T04:28:00Z2020-01-14T04:28:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript function rob(nums) { if(!nums || nums.length === 0) { return 0; } else if(nums.length <a href="https://www.cnblogs.com/rubylouvre/p/12191387.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12189760.htmlleetcode 986. Interval List Intersections - 司徒正美快慢指针法2020-01-13T14:37:00Z2020-01-13T14:37:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】快慢指针法 <a href="https://www.cnblogs.com/rubylouvre/p/12189760.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12175524.htmlleetcode 869. Reordered Power of 2 - 司徒正美```javascript function reorderedPowerOf2(N) { var a1 = N.toString().split('') a1.sort((a, b) => a.localeCompare(b) ) var s1 = a1.join('...2020-01-10T04:14:00Z2020-01-10T04:14:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript function reorderedPowerOf2(N) { var a1 = N.toString().split('') a1.sort((a, b) => a.localeCompare(b) ) var s1 = a1.join('... <a href="https://www.cnblogs.com/rubylouvre/p/12175524.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12174341.htmlleetcode 925. Long Pressed Name - 司徒正美判定是否长按 javascript var isLongPressedName = function (name, typed) { var i = 1, j = 0, n = name.length, m = typed.length; var last = name[0], iCount = 12020-01-09T18:06:00Z2020-01-09T18:06:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】判定是否长按 javascript var isLongPressedName = function (name, typed) { var i = 1, j = 0, n = name.length, m = typed.length; var last = name[0], iCount = 1 <a href="https://www.cnblogs.com/rubylouvre/p/12174341.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12159239.htmlleetcode 457. Circular Array Loop - 司徒正美先回顾一下链表的类似问题 leetcode 141 判定链表是否有环 慢指针slowPtr每次后移1个结点。快指针fastPtr每次后移2个结点 LeetCode 142 找出环的入口点(起点) 当fast按照每次2步,slow每次一步的方式走,发现fastPtr和slowPtr重合,确定了单向链表2020-01-06T16:38:00Z2020-01-06T16:38:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】先回顾一下链表的类似问题 leetcode 141 判定链表是否有环 慢指针slowPtr每次后移1个结点。快指针fastPtr每次后移2个结点 LeetCode 142 找出环的入口点(起点) 当fast按照每次2步,slow每次一步的方式走,发现fastPtr和slowPtr重合,确定了单向链表 <a href="https://www.cnblogs.com/rubylouvre/p/12159239.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12151020.htmlleetcode 1093. Statistics from a Large Sample - 司徒正美求一个数组的最小值,最大值,平均数,中位数与众数 更简洁的实现 javascript const sampleStats = function(count) { let min = Infinity; let max = Infinity; let sum = 0; let totalCount =2020-01-04T16:20:00Z2020-01-04T16:20:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】求一个数组的最小值,最大值,平均数,中位数与众数 更简洁的实现 javascript const sampleStats = function(count) { let min = Infinity; let max = Infinity; let sum = 0; let totalCount = <a href="https://www.cnblogs.com/rubylouvre/p/12151020.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12147761.htmlleetcode 881. Boats to Save People - 司徒正美使用一艘船救人,每次最多只能救两人,请问最少要几次 这是左右节点法。 javascript var numRescueBoats = function (people, limit) { people.sort((a, b) = a b) var left = 0; var right = peop2020-01-03T17:31:00Z2020-01-03T17:31:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】使用一艘船救人,每次最多只能救两人,请问最少要几次 这是左右节点法。 javascript var numRescueBoats = function (people, limit) { people.sort((a, b) = a b) var left = 0; var right = peop <a href="https://www.cnblogs.com/rubylouvre/p/12147761.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12142933.htmlleetcode 977. Squares of a Sorted Array - 司徒正美比较直观的解法 另一个,从左右两端开始比较,可能是 123与124比较,然后是 123与1222020-01-02T16:36:00Z2020-01-02T16:36:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】比较直观的解法 另一个,从左右两端开始比较,可能是 123与124比较,然后是 123与122 <a href="https://www.cnblogs.com/rubylouvre/p/12142933.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12131141.htmlleetcode 844. Backspace String Compare - 司徒正美比较两个带退格键的字符串 方法1, 从后往前遍历,记录要忽略掉的字符 方法2, 使用栈,从前往后处理2020-01-01T17:00:00Z2020-01-01T17:00:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】比较两个带退格键的字符串 方法1, 从后往前遍历,记录要忽略掉的字符 方法2, 使用栈,从前往后处理 <a href="https://www.cnblogs.com/rubylouvre/p/12131141.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12124448.htmlleetcode 1032. Stream of Characters - 司徒正美用字典树即可解决。首先在init的时候,把words中所有word逆置后存入字典树中;在query的时候,也有逆序的方式记录所有历史query过的值,同时判断其前缀是否存在于字典树中即可。2019-12-31T06:57:00Z2019-12-31T06:57:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】用字典树即可解决。首先在init的时候,把words中所有word逆置后存入字典树中;在query的时候,也有逆序的方式记录所有历史query过的值,同时判断其前缀是否存在于字典树中即可。 <a href="https://www.cnblogs.com/rubylouvre/p/12124448.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12122516.htmlleetcode 1023. Camelcase Matching - 司徒正美使用前缀树, 多个字符串匹配一个模式 javascript function Node() { this.children = {} } class Trie { constructor() { this.root = new Node() } insert(word) { var node = t2019-12-30T18:32:00Z2019-12-30T18:32:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】使用前缀树, 多个字符串匹配一个模式 javascript function Node() { this.children = {} } class Trie { constructor() { this.root = new Node() } insert(word) { var node = t <a href="https://www.cnblogs.com/rubylouvre/p/12122516.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12116957.htmlleetcode 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 =2019-12-29T14:45:00Z2019-12-29T14:45:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript var WordFilter = function (words) { this.trie = {}, idx = 0; for (let word of words) { let m = word.length; let paths = []; for (let i = <a href="https://www.cnblogs.com/rubylouvre/p/12116957.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12113344.htmlleetcode 720. Longest Word in Dictionary - 司徒正美使用前缀树 javascript function Node() { this.word = '' this.children = {} } class Trie { constructor() { this.root = new Node() } addWord(word) { var node 2019-12-28T14:35:00Z2019-12-28T14:35:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】使用前缀树 javascript function Node() { this.word = '' this.children = {} } class Trie { constructor() { this.root = new Node() } addWord(word) { var node <a href="https://www.cnblogs.com/rubylouvre/p/12113344.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12113227.htmlleetcode 692. Top K Frequent Words - 司徒正美```javascript function Node() { this.endCount = 0 this.word = '' this.children = {} } class Tire { constructor() { this.root = new Node() } addWord...2019-12-28T14:01:00Z2019-12-28T14:01:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】```javascript function Node() { this.endCount = 0 this.word = '' this.children = {} } class Tire { constructor() { this.root = new Node() } addWord... <a href="https://www.cnblogs.com/rubylouvre/p/12113227.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12112893.htmlleetcode 677. Map Sum Pairs - 司徒正美使用前缀树 或者 使用map优化一下2019-12-28T12:12:00Z2019-12-28T12:12:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】使用前缀树 或者 使用map优化一下 <a href="https://www.cnblogs.com/rubylouvre/p/12112893.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12110169.htmlleetcode 676. Implement Magic Dictionary - 司徒正美使用Tire 处理 javascript function Node(value) { this.word = null this.children = {} } class MagicDictionary { constructor() { this.root = new Node(null) }2019-12-27T16:17:00Z2019-12-27T16:17:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】使用Tire 处理 javascript function Node(value) { this.word = null this.children = {} } class MagicDictionary { constructor() { this.root = new Node(null) } <a href="https://www.cnblogs.com/rubylouvre/p/12110169.html" target="_blank">阅读全文</a>https://www.cnblogs.com/rubylouvre/p/12109753.htmlleetcode 648. Replace Words - 司徒正美将单词替换成其词根2019-12-27T13:43:00Z2019-12-27T13:43:00Z司徒正美https://www.cnblogs.com/rubylouvre/【摘要】将单词替换成其词根 <a href="https://www.cnblogs.com/rubylouvre/p/12109753.html" target="_blank">阅读全文</a>