链表
链表系列算法题
Charlesjjc
这个作者很懒,什么都没留下…
展开
-
leetcode142.环形链表II
判断是否存在环形链表,题目链接: https://leetcode-cn.com/problems/linked-list-cycle-ii/ 我的代码 public class Solution { public ListNode detectCycle(ListNode head) { if(head == null || head.next == null) return null; ListNode right = head; whi原创 2021-07-17 10:13:53 · 85 阅读 · 0 评论 -
leetcode 链表相交
上题目链接: https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci/ 这题目的介绍跟shit一样看不懂,才发现链表节点也能判断是否相等的。 上代码 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) {原创 2021-07-16 02:38:52 · 57 阅读 · 0 评论 -
leetcode19.删除链表的倒数第N个节点
题目链接: https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 先用粗糙的思路秒了 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val原创 2021-07-16 01:25:05 · 47 阅读 · 0 评论 -
leedcode24.两两交换链表中的节点
题目链接: https://leetcode-cn.com/problems/swap-nodes-in-pairs/ 代码: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode原创 2021-07-16 01:06:30 · 32 阅读 · 0 评论 -
leetcode206.反转链表
非常简单 非常简单,上链接: https://leetcode-cn.com/problems/reverse-linked-list/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * Li.原创 2021-07-15 21:48:31 · 33 阅读 · 0 评论 -
leetcode707.设计链表
链表的基本操作实现 https://leetcode-cn.com/problems/design-linked-list/ 上代码 class MyLinkedList { int size; ListNode head; public MyLinkedList() { size = 0; head = new ListNode(0); } //特别注意index >= size,为什么要加上=,因为inde原创 2021-07-15 20:11:10 · 86 阅读 · 0 评论 -
leetcode203.移除链表元素
终于进入链表了,来个开胃菜: https://leetcode-cn.com/problems/remove-linked-list-elements/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } *原创 2021-07-15 14:37:46 · 41 阅读 · 0 评论