![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode笔记
麦芒.com
这个作者很懒,什么都没留下…
展开
-
滑动窗口 力扣最短超串
最近遇到两道滑动窗口的题都没有解出来,借此来学习这个早已熟悉却不怎么会用的概念。Sliding Window:其实看到类似满足xx的最小区间的子串这类问题自然可以想到滑动窗口。一般滑动窗口要维护两个指针,l,r1.当窗口内到元素未达到条件时, r++2.当窗口内到元素达到条件时,l++function slideWindow(nums){ let n = nums.length() let l = 0, r = 0, ans = 0 while(r < n){ while(nums原创 2021-04-28 12:32:47 · 77 阅读 · 0 评论 -
给定两个树的节点,求它们的最短距离 JS
//method 1const shortestDistance = function(root, p, q) { // 最近公共祖先 let zx = lowestCommonAncestor(root,p,q) let pathp = [], pathq = [] getPath(zx,p,pathp) getPath(zx,q,pathq) return pathp.length + pathq.length}// 最近公共祖先const lowestCommonAncestor原创 2021-04-26 09:43:59 · 219 阅读 · 0 评论 -
面试题 08.14. 布尔运算 JS
/** * @param {string} s * @param {number} result * @return {number} */var countEval = function(s, result) { let n = s.length // 创建三维数组 let dp = new Array(n).fill(0).map(() => new Array(n).fill(0).map(() => new Array(2).fill(0)))原创 2021-04-25 17:05:47 · 160 阅读 · 0 评论 -
实现数组a = [1,[2,[3,[4,null]]]]转换[4,[3,[2,[1,null]]]]
(function main() { let a = [1,[2,[3,[4,null]]]] // 实现数组 b = [4,[3,[2,[1,null]]]] let path = [] while(a){ path.push(a.shift()) a = a[0] } console.log(path) let real = [a] while(path.length){ let arr =原创 2021-04-25 16:36:07 · 611 阅读 · 0 评论 -
递归 + 力扣(链表反转,最近公共祖先,递增顺序搜索树)
因为最近无次序刷力扣又刷到了当时的递归,每次看递归的代码都会有一定的理解,但隔了一段时间又没啥思路。先来看一下递归的模版结构:// JavaScriptfunction recur(level, param) { // 递归的终止条件 if (level > MAX_LEVEL) { return; } // 处理当前层逻辑 process(level, param); // 下探到下一层 recur( level: level + 1,原创 2021-04-23 10:14:02 · 105 阅读 · 0 评论 -
力扣刷题笔记
1.如何将矩阵转化为数组:import itertoolsjz=[ [1,2,3], [2,3,4], [5,6,7]]cur=list()for i in itertools.chain.from_iterable(jz): cur.append(i)print(cur) # numpy import numpy as np row, col = len(nums), len(nums[0]) return原创 2020-09-30 08:08:36 · 101 阅读 · 0 评论