ICode9

精准搜索请尝试: 精确搜索
  • [编程题] 反转单链表2022-09-13 20:35:42

    interface LinkedList { val: number next: LinkedList | null } function reverseLinkedlist(head: LinkedList): LinkedList { if (head === null || head.next === null) { return head } const prev = reverseLinkedlist(head.next) hea

  • 删除链表结点类问题2022-08-21 03:01:59

    删除链表结点 NO1. 删除链表倒数第 k个结点 给定一个链表,删除链表的倒数第 n 个节点并返回链表的头指针。要求:空间复杂度 \(O(1)\),时间复杂度 \(O(n)\) 如果倒数第 k 个结点刚好是头结点,那头结点需要特殊处理。为了各个结点能等同操作,设置一个虚拟头结点。 寻找倒数第 k 个结点

  • 手写 js数组reduce2022-08-18 01:33:05

    function reduce(list, fn, ...init) { let prev = init.length > 0 ? init[0] : list[0]; for (let i = init.length > 0 ? 0 : 1; i < list.length; i++) { prev = fn(prev, list[i], i); } return prev; } console.log( reduce([1, 2

  • LeetCode 反转链表算法题解 All In One2022-08-15 23:30:09

    LeetCode 反转链表算法题解 All In One js / ts 实现反转链表 反转链表原理 图解 双指针,swap 交换 // 反转 双指针 // swap: a = b; c = a; b = c; let prev: ListNode | null = null; let cur: ListNode | null = head; // while(cur) { // // ES5 swap 缓存引用

  • [Algorithm] Doubly Linked list construction2022-08-04 01:31:07

    // This is an input class. Do not edit. class Node { constructor(value) { this.value = value; this.prev = null; this.next = null; } } // Feel free to add new properties and methods to the class. class DoublyLinkedList { constructor() {

  • 从链表中删除元素2022-07-26 22:03:19

    //删除链表中第index(o-based)个位置的元素,返回删除的全速 //在链表中不是一个常用的操作,练习用:) public E remove(int index) { if (index < 0 || index > size) throw new IllegalArgumentException("Set failed.Illegal index."); N

  • LeetCode 945. Minimum Increment to Make Array Unique2022-07-19 08:34:53

    原题链接在这里:https://leetcode.com/problems/minimum-increment-to-make-array-unique/ 题目: You are given an integer array nums. In one move, you can pick an index i where 0 <= i < nums.length and increment nums[i] by 1. Return the minimum number of mov

  • react hook 实现use-watch2022-07-14 20:33:52

    import { useEffect, useRef } from 'react'; const defaultCompare = (prev, next) => prev === next; export const useWatch = ( callback, value, { initialValue = '', compare = defaultCompare } = {}, ) => { const prevValue = us

  • 206.反转链表2022-07-14 11:32:41

    206.反转链表 给你单链表的头结点head,请你反转链表,并返回反转后的链表 输入:head = [1,2,3,4,5] 输出:[5,4,3,2,1] 1 ——> 2 输入:head = [1,2] 2 ——> 1 输出:[2,1] 提示: 链表中节点的数目范围是[0,5000] -5000 <= Node.val <= 5000 java: 迭代 /** *

  • 记录信息(record)2022-07-06 11:39:02

    题目描述 利用动态链表输入、存储若干学生的信息,包括学号、姓名、性别、年龄、成绩,再按输入顺序倒叙输出。其中,学号长度不超过20个字符,姓名长度不超过40个字符,性别为一个字母f或m,年龄和成绩为一个整数。 输入 若干行,每一行都是一个学生的信息。例如 20170118 zhangsan m 15 100,其

  • Reverse Linked List2022-07-03 14:04:54

    Source Reverse a linked list. Example For linked list 1->2->3, the reversed linked list is 3->2->1 Challenge Reverse it in-place and in one-pass 题解1 - 非递归 联想到同样也可能需要翻转的数组,在数组中由于可以利用下标随机访问,翻转时使用下标即可完成。而在单向

  • 【剑指Offer 24】反转链表2022-06-26 23:35:48

    双指针 /** * 剑指 Offer 24. 反转链表 * https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/ * * 思路:双指针 * */ public class Solution1 { public ListNode reverseList(ListNode head) { if (head == null || head.next == null) { retu

  • 【剑指Offer 22】链表中倒数第k个节点2022-06-26 22:00:57

    /** * 剑指 Offer 22. 链表中倒数第k个节点 * https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/ * * 思路:快慢指针 * */ public class Solution { public ListNode getKthFromEnd(ListNode head, int k) { ListNode prev = head;

  • 反转链表2022-06-26 00:00:14

    来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/reverse-linked-list 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 点击查看代码 public ListNode reverseList(ListNode head) { if(head == null){ return head; }

  • 查询连续出现的数字次数为3的num2022-06-25 16:03:00

    #连续出现的数字次数3 Mysql #变量使用方式 @pre :=赋值select Num, case when @prev = Num then @count := @count + 1 when (@prev := Num) is not null then @count := 1 end as CNT from Log #解析: id num 1 12 13 14 25 16 27 2## 数据库查询方式一

  • 18.移除链表元素2022-06-18 20:37:31

    203. 移除链表元素 给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。   示例 1: 输入:head = [1,2,6,3,4,5,6], val = 6 输出:[1,2,3,4,5] 示例 2: 输入:head = [], val = 1 输出:[] 示例 3: 输入:head = [7,7,7,7], v

  • js中数组reduce的使用原来这么简单2022-06-15 20:32:10

    reduce 的学习方法 array.reduce(callback(prev, currentValue, index, arr), initialValue) //简写就是下面这样的 arr.reduce(callback,[initialValue]) callback (执行数组中每个值的函数,包含四个参数) 1、prev (上一次回调返回的值,或者是提供的初始值(initialValue)) 2、currentV

  • LeetCode刷题-#25 Reverse Nodes in k-Group2022-06-13 20:36:42

    描述 Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is. You may not alter the values in the nodes, only node

  • el-tree节点模拟双击事件2022-06-10 19:03:57

    需求描述 el-tree组件节点默认展开,单击节点不会触发伸缩,双击节点获取当前节点的数据。 问题解决 el-tree 默认展开并设置阻止单击节点自动展开或收缩 <el-tree default-expand-all :expand-on-click-node="false" @node-click="handleNode"> 添加双击事件 const n = { count

  • LeetCode 0146 LRU Cache2022-05-23 08:32:30

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 HashMap + 双向链表 用HashMap存储元素。 put一个元素,头插。如果get某个元素,就把这个元素移动到链表头部。当存满的时候,就移掉表尾。 2、代码实现 package Q0199.Q0146LRUCache; import java.util.HashMap; import java.util.

  • 前端电商 sku 的全排列算法2022-05-03 14:33:03

    需求 需求描述起来很简单,有这样三个数组: let names = ["iPhone",'iPhone xs'] let colors = ['黑色','白色'] let storages = ['64g','256g'] 需要把他们的所有组合穷举出来,最终得到这样一个数组: [ ["iPhone X", "黑色", "64g"

  • js reduce用法详解2022-04-27 00:31:06

    前言    reduce() 方法对数组中的每个元素执行一个由您提供的reduce函数(升序执行),将其结果汇总为单个返回值。reduce方法可做的事情特别多,就是循环遍历能做的,reduce都可以做,比如数组求和、数组求积、数组中元素出现的次数、数组去重等等。 语法 arr.reduce(function(prev,cur,i

  • 二级指针在链表中的妙用2022-04-23 19:33:22

    重要结论 有效地利用二级指针,将其作为管理和操作链表的首要选项 问题的引入 在对链表进行删除操作时,函数参数的参数为二级指针,代码如下: struct single_list* del(struct single_list **prev) { struct single_list *tmp; if(!prev) return NULL; if(*prev ==

  • 双向链表2022-04-22 13:31:16

    1 #include <stdio.h> 2 #include <stdlib.h> 3 4 // 节点结构 5 6 struct LinkedList 7 { 8 // 节点 9 struct Node 10 { 11 int item = 0; 12 Node *prev; 13 Node *next; 14 15 // 得到一个新节点

  • 对象扁平化2022-04-11 08:33:07

    递归 function flat(obj) { // 你的代码 const back = {}; recursion(obj, null); function recursion(o, prev) { for (let key in o) { if (o[key] instanceof Object) { if (prev === null) { recurs

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有