javascript
文娘
这个作者很懒,什么都没留下…
展开
-
lc24两两交换链表中的节点
递归法。官方题解非常好理解,head是每一组的第一个节点,newHead是每一组的第二个节点,思路是将head的next指向下一组的头节点,将newHead的next指向head,并且返回newHead,这样就完成了每一组两两相邻的交换。var swapPairs = function(head) { if(head===null||head.next==null) return head var newHead=head.next head.next=swapPairs(new原创 2022-01-06 23:24:26 · 319 阅读 · 0 评论 -
lc206反转链表
递归与非递归写法递归var reverseList=function(head){ if(head===null||head.next===null) return head if(head.next==null) return head//如果到了链表尾,返回head var last=reverseList(head.next)//否则将节点反转 head.next.next=head head.next=null return last}非递归原创 2022-01-05 20:53:38 · 233 阅读 · 0 评论 -
lc3.无重复字符的最长子串
没思路,官方题解是滑动窗口做的,改天写上。让我记下学长写的题解,很好看懂。var lengthOfLongestSubstring = function(s) { let m=new Map()//map存储字符对应最后一次出现的下标 let max=0//最长子串长度 let start=0//最长子串的开始字符下标 for(let i=0;i<s.length;i++){ if(m.has(s[i])){//如果遇到了重复的字符,更新最长子串的开原创 2022-01-05 17:57:25 · 123 阅读 · 0 评论 -
闭包输出循环中正确的值
https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/43一for(var i=0;i<5;i++){ setTimeout((i)=>{ console.log(i) },1000,i)}二for(var i=0;i<5;i++){ (function(j){ setTimeout(()=>{ console.lo原创 2021-04-27 18:03:43 · 78 阅读 · 0 评论 -
实现
面试题 实现const a = [1, 2, 3, 4, 5];// Implement thisa.multiply();console.log(a); // [1, 2, 3, 4, 5, 1, 4, 9, 16, 25]要求的是对a修改const a = [1, 2, 3, 4, 5];// Implement thisArray.prototype.multiply = function() { this.forEach(x => this.push(x * x))原创 2021-04-27 17:08:51 · 74 阅读 · 0 评论 -
2020-12-4对浏览器console控制台输出undefined的分析
https://blog.csdn.net/qq_40938301/article/details/87489046mark。原创 2020-12-04 10:54:10 · 242 阅读 · 0 评论 -
2020-11-11
学习廖雪峰的教程,看到arguments关键字。有这样一段代码:var abs=function(a,b,c){ if(arguments.length==2){ c=b; b=null; } console.log(a,b,c);};abs(10,9);输出是10 null 9现在不太能体会到这么做的必要和好处。...原创 2020-11-11 15:26:57 · 42 阅读 · 0 评论 -
2020-11-06javascript使用多行字符串的几种方式
先贴上别人的链接,慢慢弄。http://jser.me/2013/08/20/javascript%E7%9A%84%E5%87%A0%E7%A7%8D%E4%BD%BF%E7%94%A8%E5%A4%9A%E8%A1%8C%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%96%B9%E5%BC%8F.html原创 2020-11-06 10:08:49 · 113 阅读 · 0 评论