![](https://img-blog.csdnimg.cn/20190918140213434.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
chain algorithm
文章平均质量分 81
算法与数据结构下的与链表相关的算法
乌托邦钢铁侠
Practice makes perfect, fighting with my time .
1. Java
2. English foolish
3. Love riding
展开
-
数据结构单链表操作(增加、删除、遍历节点)(python)
使用python实现一个链表,需要具备如下功能:1. 可以在头部、尾部或者指定位置插入节点。2. 遍历链表。# 初始化一个节点class Node(object): def __init__(self, val): self.val = val self.next = None# 定义链表类class SingleLinkedList(object): def __init__(self): self.heade.原创 2020-10-09 16:26:32 · 3272 阅读 · 0 评论 -
手写简易版HashMap
前言 我们发现HashMap在jdk 1.8之后用了数组+链表+红黑树的结构,为了加深对HashMap底层设计的理解,自己也读了一些hashmap相关的源码,因此想通过手写hashmap去理其底层的操作原理。HashMap源码解析 目标: 基于数组+链表结构实现一个HashMap,包含get()、put()、remove()方法。 环境: jdk1.8 知识储备: hashcode, 幂等性, 数组,链表,红黑树。 原理: Hash...原创 2021-05-16 10:26:36 · 2458 阅读 · 5 评论 -
图解LRU算法
一、什么是LRU算法? LRU 全称Least Recently Used, LRU算法是一种操作系统层面上的页面置换算法,将最近最久未使用的页面进行淘汰。二、基于双向链表+Map实现LRU算法 为什么选用双向链表做cache? 因为双向链表能够很方便地找到上一个节点和下一个节点,对节点的操作相对来说比较容易。单向的不能找到上一个节点,在操作时不能提供当前节点的上一个节点遍历。 1. 用双向链表看成cache缓存, 数据...原创 2021-05-07 09:15:07 · 5200 阅读 · 1 评论 -
阿里面试题: 将两个升序链表合并成一个升序链表
题目将两个升序链表合并,合并后还是一个升序列表,尽量用最小的时间复杂度。思路一 两个链表合成一个链表,可以将两个链表打散,然后按照大小顺序放入到一个数组里,冒泡排序后,将节点串起来,这样就可以实现一个升序链表。思路二 思路一方法虽然可行,但是时间复杂度和空间复杂度import chain.ReverseList;/** * @decription: * @author: zhengbing.zhang * @date: 2021...原创 2021-07-09 17:56:59 · 4302 阅读 · 0 评论 -
面试题: 怎么将单链表反转?
package com.example.file;import java.lang.reflect.Array;import java.util.ArrayList;import java.util.Collections;import java.util.List;public class ReverseListTest { public static class Node{ int val; Node next; Node(int x) { ...原创 2020-07-03 20:59:12 · 301 阅读 · 0 评论 -
两链表相加问题
一、题目两链表相加问题, 满10进1例如: (4->2->1) +(6->3->7),得到结果为: 0->6->8得到结果860假设链表的长度是相等的, 不考虑表尾溢出的情况。二、思路三、完整代码package leetcode100;/** * @decription: * @author: zhengbing.zhang * @date: 2021/7/12 17:40 * 两链表相加问题, 满10进1原创 2021-07-14 16:12:00 · 1805 阅读 · 0 评论 -
Delete Desined Node In The Linked List(链表节点删除问题)
Question Given a linked list, please remove the n -th node from the start of list and return its head.Thinking We know The linked list consists of many nodes. but we can not directly get a the location of a node, so we must traverse ...原创 2021-08-19 14:02:51 · 133 阅读 · 0 评论 -
Invert K Nodes In Linked List(倒置链表的K个节点)
Question Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. K is a positive integer and is less than or equal to the length of linked list. If the number of nodes is not a mutiple of k then left-out ...原创 2021-08-20 16:12:40 · 225 阅读 · 0 评论 -
面试官: 如何用Java实现一个栈?
面试官看到了最后,嗯嗯... 小伙子等后续通知把~原创 2022-04-20 20:19:25 · 1473 阅读 · 0 评论 -
Leetcode 02: 两数相加(中等)
leetCode连接:https://leetcode-cn.com/problems/add-two-numbers一、题目描述给你两个非空 的链表,表示两个非负的整数。它们每位数字都是按照逆序的方式存储的,并且每个节点只能存储一位数字。请你将两个数相加,并以相同形式返回一个表示和的链表。你可以假设除了数字 0 之外,这两个数都不会以 0开头。二、 解决思路1) 采用递归思想求解。2) 维护一个主链表,我在此题中用的是l1作为主链表,将求得的和放在该链表上。......原创 2022-04-23 23:14:22 · 272 阅读 · 0 评论