Shu-How Zの小窝

Loading...

随笔分类 -  Leetcode-javascript

摘要:/** * @param {string} s * @return {number} */ var myAtoi = function(s) { const reg = /\s*([-\+]?[0-9]*).*/; const res = s.match(reg); let num if(res){ 阅读全文
posted @ 2026-09-02 21:52 KooTeam 阅读(6) 评论(0) 推荐(0)
摘要:var WordDictionary = function() { this.words=[] }; /** * @param {string} word * @return {void} */ WordDictionary.prototype.addWord = function(word) { 阅读全文
posted @ 2026-08-26 22:34 KooTeam 阅读(4) 评论(0) 推荐(0)
摘要:/** * @param {string} s * @return {boolean} */ var validPalindrome = function(s) { let len=s.length let j=0 let k=len-1 while(j<k && s[j]==s[k]){ j++ 阅读全文
posted @ 2026-08-18 12:45 KooTeam 阅读(9) 评论(0) 推荐(0)
摘要:/** * @param {number[]} nums * @return {number[][]} */ var threeSum = function(nums) { let res=[] let len=nums.length nums=nums.sort((a,b)=>a-b) for(l 阅读全文
posted @ 2026-08-10 13:18 KooTeam 阅读(5) 评论(0) 推荐(0)
摘要:Leetcode88 合并两个数组 合并两个有序数组 /** * @param {number[]} nums1 * @param {number} m * @param {number[]} nums2 * @param {number} n * @return {void} Do not ret 阅读全文
posted @ 2026-08-03 22:21 KooTeam 阅读(5) 评论(0) 推荐(0)
摘要:138. 随机链表的复制 138.复制带随机指针的链表 0:45:56 var copyRandomList = function(head) { if(!head) return null; //创建两个指针,一个指向头节点 let p=head,q; //遍历整个链表,复制每个节点,并将值全部复 阅读全文
posted @ 2026-07-01 20:07 KooTeam 阅读(6) 评论(0) 推荐(0)
摘要:86. 分隔链表 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next undefine 阅读全文
posted @ 2026-05-25 18:11 KooTeam 阅读(13) 评论(0) 推荐(0)
摘要:82. 删除排序链表中的重复元素 II 1:49:16 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.ne 阅读全文
posted @ 2026-05-19 19:18 KooTeam 阅读(14) 评论(0) 推荐(0)
摘要:83. 删除排序链表中的重复元素 1:37:19 /** * @param {ListNode} head * @return {ListNode} */ var deleteDuplicates = function(head) { if(!head) return null; let pre=h 阅读全文
posted @ 2026-05-11 19:11 KooTeam 阅读(13) 评论(0) 推荐(0)
摘要:function ListNode(val, next) { this.val = (val undefined ? 0 : val) this.next = (next undefined ? null : next) } /** * Definition for singly-linked li 阅读全文
posted @ 2026-05-07 16:55 KooTeam 阅读(9) 评论(0) 推荐(0)
摘要:24. 两两交换链表中的节点 0:58:19 function ListNode(val, next) { this.val = (val undefined ? 0 : val) this.next = (next undefined ? null : next) } /** * @param { 阅读全文
posted @ 2026-04-27 17:56 KooTeam 阅读(67) 评论(0) 推荐(0)
摘要:61 旋转链表 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next undefined 阅读全文
posted @ 2026-04-20 21:30 KooTeam 阅读(13) 评论(0) 推荐(0)
摘要:LeetCode-25 K个一组反转链表 1:52:03 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.n 阅读全文
posted @ 2026-04-15 17:20 KooTeam 阅读(12) 评论(0) 推荐(0)
摘要:var reverseBetween = function(head, left, right) { if(!head)return null; let ret=new ListNode(-1,head),pre=ret,cnt=right-left+1; while(--left){ pre=pr 阅读全文
posted @ 2026-04-08 19:43 KooTeam 阅读(11) 评论(0) 推荐(0)
摘要:206. 反转链表 1:17:41 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next 阅读全文
posted @ 2026-04-03 18:27 KooTeam 阅读(11) 评论(0) 推荐(0)
摘要:/** * @param {number} n * @return {boolean} */ var isHappy = function(n) { let pre=n,cur=getNext(n); while(cur!==pre && cur!==1){ pre=getNext(pre) cur 阅读全文
posted @ 2025-12-11 18:13 KooTeam 阅读(23) 评论(0) 推荐(0)
摘要:var detectCycle = function(head) { if(!head)return null; let pre=head,cur=head; while(cur&&cur.next){ pre=pre.next; cur=cur.next.next; if(pre cur){ le 阅读全文
posted @ 2025-11-03 18:57 KooTeam 阅读(16) 评论(0) 推荐(0)
摘要:685.冗余连接 4:03 // 定义并查集类 class UnionFind{ // 构造函数初始化并查集 constructor(n){ this.parent = new Array(n).fill(0).map((item,index)=>index) this.rank = new Arr 阅读全文
posted @ 2025-09-13 19:43 KooTeam 阅读(23) 评论(0) 推荐(0)
摘要:765.情侣牵手 3:32 //遍历row数组,每次都去取出来两个人,我们知道正常的情侣他的编号从0开始的 //一堆正确的情侣就是一个是偶数一个是奇数;并且奇数=偶数+1;和奇数/2.==偶数/2;这个时候才是情侣;否则就需要将两个编号除以2之后的结果进行联通,进行交换次数: //当N-1对配对成功 阅读全文
posted @ 2025-05-27 16:41 KooTeam 阅读(41) 评论(0) 推荐(0)
摘要:721.账户合并 2:19:44 // 定义并查集类 class UnionFind{ // 构造函数初始化并查集 constructor(n){ this.parent = new Array(n).fill(0).map((item,index)=>index) this.rank = new 阅读全文
posted @ 2025-05-06 18:26 KooTeam 阅读(46) 评论(0) 推荐(0)