摘要: 19.删除链表的倒数第N个节点https://leetcode.cn/problems/remove-nth-node-from-end-of-list/ 思路:使用前后指针,当删除倒数第N个节点时,快慢指针之间应该间隔N个元素,当快指针到达链尾时,慢指针next指向所要删除节点。 时间复杂度:O( 阅读全文
posted @ 2024-01-13 15:13 糟糕的家伙 阅读(16) 评论(0) 推荐(0)
摘要: 203.移除链表元素https://leetcode.cn/problems/remove-linked-list-elements/ 思路:没什么好说的 /** * Definition for singly-linked list. * public class ListNode { * int 阅读全文
posted @ 2024-01-12 14:58 糟糕的家伙 阅读(7) 评论(0) 推荐(0)
摘要: 977.有序数组的平方[https://leetcode.cn/problems/squares-of-a-sorted-array/] 思路:因为数组是非递减,数组有正有负,找到第一个非负数设为i,i将数组划分为前部分的负数组,后部分的非负数组,使用辅助数组将原数组平方部分存储,后部分使用正序存储 阅读全文
posted @ 2024-01-11 23:55 糟糕的家伙 阅读(10) 评论(0) 推荐(0)
摘要: 704.二分查找 [https://leetcode.cn/problems/binary-search/description/] 思路: 二分查找适用于在有序数组中查找目标值,左边边界为left,右边边界为right,每次使用middle=(right+left)/2,将原数组划分为[left, 阅读全文
posted @ 2024-01-10 16:25 糟糕的家伙 阅读(13) 评论(0) 推荐(0)