摘要: 相交链表 点击查看代码 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = nul 阅读全文
posted @ 2025-12-25 23:15 柳成荫y 阅读(0) 评论(0) 推荐(0)
摘要: 438.找到字符串中所有的字母异位词 思路:固定窗口 点击查看代码 class Solution { public List<Integer> findAnagrams(String s, String p) { List<Integer> result = new ArrayList<>(); i 阅读全文
posted @ 2025-12-24 18:42 柳成荫y 阅读(2) 评论(0) 推荐(0)
摘要: 209. 长度最小的子数组 点击查看代码 class Solution { public int minSubArrayLen(int target, int[] nums) { int n = nums.length; int res = Integer.MAX_VALUE; int sum = 阅读全文
posted @ 2025-12-21 22:33 柳成荫y 阅读(3) 评论(0) 推荐(0)
摘要: 盛最多水的容器 点击查看代码 class Solution { public int maxArea(int[] height) { int n = height.length; int l = 0; int r = n - 1; int res = Integer.MIN_VALUE; while 阅读全文
posted @ 2025-12-20 19:41 柳成荫y 阅读(3) 评论(0) 推荐(0)
摘要: 四数之和 点击查看代码 class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { int n = nums.length; Arrays.sort(nums); List<List<Integer>> 阅读全文
posted @ 2025-12-19 23:37 柳成荫y 阅读(2) 评论(0) 推荐(0)
摘要: 三数之和 点击查看代码 class Solution { public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(nums); int n = nums.length; List<List<Integer>> res = new A 阅读全文
posted @ 2025-12-18 21:53 柳成荫y 阅读(3) 评论(0) 推荐(0)
摘要: 三数之和 双指针 转换成两数之和问题。 最接近的三数之和 双指针 三数之和基础上增加一个minDiff判断。 阅读全文
posted @ 2025-12-10 17:24 柳成荫y 阅读(5) 评论(0) 推荐(0)
摘要: 最长连续序列 哈希 避免了重复计算同一序列,只有当符合起点的条件时候才遍历,也就是-1不存在。 关键通过判断"前一个元素是否存在"来识别序列起点,从而确保每个序列只被完整遍历一次。 两数之和 双指针 对于一个有序数组来讲,利用有序数组的性质,左右指针相向而行。 根据左+右和目标值的情况 判断指针移动 阅读全文
posted @ 2025-12-09 19:31 柳成荫y 阅读(4) 评论(0) 推荐(0)
摘要: 两数之和 方法:哈希表 创建一个哈希表 (HashMap),key存储数组元素的值 (val) 和value其对应的索引 (idx); 字母异位词分组 方法:哈希表 创建一个哈希表 (HashMap),key存储排序后的字符串,value存储当前字符串对应的异位词分组; 阅读全文
posted @ 2025-12-08 16:57 柳成荫y 阅读(5) 评论(0) 推荐(0)
摘要: 点击查看代码 //闭合区间二分查找 public int Binary_Search_1(int[] num, int target){ int left = 0; int right = num.length - 1; while(left <= right){ int mid = left + 阅读全文
posted @ 2025-11-23 17:38 柳成荫y 阅读(6) 评论(0) 推荐(0)