双向链表java实现

一 双向链表简介

双向链表的定义是,一个节点有两个方向,分别储存当前节点的前驱节点,和后续节点;双向链表的删除只需要指定前驱节点,或者后续节点就可以进行删除操作;但是缺点也很明显每次添加节点时都需要2个指向,额外增加了内存空间消耗;

二 双向链表的实现

3.1 定义链表节点

  1. 定义data存储数据,知识追寻者使用的时int类型,读者可以改为object类型;
  2. 定义前驱节点previous
  3. 定义后续节点next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* @Author lsc
* <p> 双向链表节点 </p>
*/
public class DoubleNode {

//数据
private Integer data;
//后续节点节点
private DoubleNode next;
//前驱节点
private DoubleNode previous;
// 省略set get
}

leetcode 1-50

最近更新: 2020-6-6 upds。

1. 两数之和

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

leetcode 1-50

1. 两数之和

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×