随笔分类 - 每日LC
每日一题,周赛笔记
摘要:lc25 k个一组反转单链表 class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode dummy = new ListNode(0, head); ListNode pre = dummy; wh
阅读全文
摘要:lc21 合并两个有序链表 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { thi
阅读全文
摘要:lc15 三数之和 class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> ans = new ArrayList<>(); Arrays.sort(nums); for (int
阅读全文
摘要:lc215 数组中的第k个最大大元素 快排解法 class Solution { public int findKthLargest(int[] nums, int k) { return findKthLargest(nums, k-1, 0, nums.length-1); } public i
阅读全文
摘要:lc6190找到所有好下标 class Solution { public List<Integer> goodIndices(int[] nums, int k) { int[] left = new int[nums.length], right = new int[nums.length];
阅读全文
摘要:lc146 LRU缓存 class LRUCache { class Node { int key; int value; Node prev; Node next; public Node(){ } public Node(int key, int value){ this.key = key;
阅读全文
摘要:lc3 无重复字符的最长子串 滑动窗口 维护不重复的集合,指针向右平移 class Solution { public int lengthOfLongestSubstring(String s) { Set<Character> set = new HashSet<>(); int n = s.l
阅读全文
摘要:lc5 最长回文子串 1 动态规划 class Solution { public String longestPalindrome(String s) { int len = s.length(); if (len < 2) { return s; } int maxLen = 1, begin
阅读全文
摘要:模拟 lc1 两数之和 class Solution { public int[] twoSum(int[] nums, int target) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i = 0; i < nums.l
阅读全文
摘要:lc206 反转链表 class Solution { public ListNode reverseList(ListNode head) { ListNode prev = null; ListNode curr = head; while (curr != null) { ListNode n
阅读全文

浙公网安备 33010602011771号