随笔分类 - 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){
阅读全文
摘要:var WordDictionary = function() { this.words=[] }; /** * @param {string} word * @return {void} */ WordDictionary.prototype.addWord = function(word) {
阅读全文
摘要:/** * @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++
阅读全文
摘要:/** * @param {number[]} nums * @return {number[][]} */ var threeSum = function(nums) { let res=[] let len=nums.length nums=nums.sort((a,b)=>a-b) for(l
阅读全文
摘要:Leetcode88 合并两个数组 合并两个有序数组 /** * @param {number[]} nums1 * @param {number} m * @param {number[]} nums2 * @param {number} n * @return {void} Do not ret
阅读全文
摘要:138. 随机链表的复制 138.复制带随机指针的链表 0:45:56 var copyRandomList = function(head) { if(!head) return null; //创建两个指针,一个指向头节点 let p=head,q; //遍历整个链表,复制每个节点,并将值全部复
阅读全文
摘要:86. 分隔链表 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next undefine
阅读全文
摘要:82. 删除排序链表中的重复元素 II 1:49:16 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.ne
阅读全文
摘要:83. 删除排序链表中的重复元素 1:37:19 /** * @param {ListNode} head * @return {ListNode} */ var deleteDuplicates = function(head) { if(!head) return null; let pre=h
阅读全文
摘要:function ListNode(val, next) { this.val = (val undefined ? 0 : val) this.next = (next undefined ? null : next) } /** * Definition for singly-linked li
阅读全文
摘要:24. 两两交换链表中的节点 0:58:19 function ListNode(val, next) { this.val = (val undefined ? 0 : val) this.next = (next undefined ? null : next) } /** * @param {
阅读全文
摘要:61 旋转链表 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next undefined
阅读全文
摘要:LeetCode-25 K个一组反转链表 1:52:03 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.n
阅读全文
摘要: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
阅读全文
摘要:206. 反转链表 1:17:41 /** * Definition for singly-linked list. * function ListNode(val, next) { * this.val = (val undefined ? 0 : val) * this.next = (next
阅读全文
摘要:/** * @param {number} n * @return {boolean} */ var isHappy = function(n) { let pre=n,cur=getNext(n); while(cur!==pre && cur!==1){ pre=getNext(pre) cur
阅读全文
摘要: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
阅读全文
摘要:685.冗余连接 4:03 // 定义并查集类 class UnionFind{ // 构造函数初始化并查集 constructor(n){ this.parent = new Array(n).fill(0).map((item,index)=>index) this.rank = new Arr
阅读全文
摘要:765.情侣牵手 3:32 //遍历row数组,每次都去取出来两个人,我们知道正常的情侣他的编号从0开始的 //一堆正确的情侣就是一个是偶数一个是奇数;并且奇数=偶数+1;和奇数/2.==偶数/2;这个时候才是情侣;否则就需要将两个编号除以2之后的结果进行联通,进行交换次数: //当N-1对配对成功
阅读全文
摘要:721.账户合并 2:19:44 // 定义并查集类 class UnionFind{ // 构造函数初始化并查集 constructor(n){ this.parent = new Array(n).fill(0).map((item,index)=>index) this.rank = new
阅读全文

浙公网安备 33010602011771号