![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
weixin_43826142
这个作者很懒,什么都没留下…
展开
-
刷题
2021.3.22295. 数据流的中位数 class MedianFinder { private PriorityQueue<Integer> large; private PriorityQueue<Integer> small; /** * initialize your data structure here. */ public MedianFinder()原创 2021-03-25 21:29:56 · 119 阅读 · 0 评论 -
去重
2021.3.2426. 删除有序数组中的重复项 class Solution { public int removeDuplicates(int[] nums) { int n = nums.length; if (n == 0) { return 0; } int slow = 0, fast = 1; while (fast原创 2021-03-25 21:29:34 · 114 阅读 · 0 评论 -
O(1)查找/删除数组的任意元素
2021.3.24380. 常数时间插入、删除和获取随机元素 class RandomizedSet { private LinkedList<Integer> nums; private Map<Integer, Integer> valToIndex; private Random rand = new Random(); /** * Initialize your data str原创 2021-03-25 21:24:25 · 345 阅读 · 0 评论 -
双指针技巧
2021.3.23167. 两数之和 II - 输入有序数组 class Solution { public int[] twoSum(int[] numbers, int target) { int left = 0, right = numbers.length - 1; while (left < right) { int sum = numbers[left] + numbers[rig原创 2021-03-25 21:17:38 · 73 阅读 · 0 评论 -
二分搜索
2021.3.23875. 爱吃香蕉的珂珂 class Solution { public int minEatingSpeed(int[] piles, int h) { int left = 1, right = Arrays.stream(piles).max().getAsInt() + 1; while (left < right) { int mid = left + (right原创 2021-03-25 21:14:59 · 58 阅读 · 0 评论 -
单调队列
2021.3.23239. 滑动窗口最大值 class Solution { class MonotonicQueue { LinkedList<Integer> q = new LinkedList<>(); public void push(int n) { while (!q.isEmpty() && q.getLast() < n) {原创 2021-03-25 21:13:04 · 35 阅读 · 0 评论 -
单调栈
2021.3.23下一个更大元素 II class Solution { public int[] nextGreaterElements(int[] nums) { int n = nums.length; int[] res = new int[n]; Stack<Integer> s = new Stack<>(); for (int i = 2 * n原创 2021-03-25 21:10:59 · 51 阅读 · 0 评论 -
回溯算法
2021.3.2578. 子集 class Solution { List<List<Integer>> res = new LinkedList<>(); public List<List<Integer>> subsets(int[] nums) { LinkedList<Integer> track = new LinkedList<>();原创 2021-03-25 21:04:21 · 49 阅读 · 0 评论 -
LRU和LFU缓存机制
2021.3.19146. LRU 缓存机制 class LRUCache { int capacity; LinkedHashMap<Integer, Integer> cache = new LinkedHashMap<>(16,0.75f,true); public LRUCache(int capacity) { this.capacity = capacity; }原创 2021-03-20 08:28:25 · 98 阅读 · 0 评论 -
链表
2021.3.19206. 反转链表 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.va原创 2021-03-19 09:40:15 · 63 阅读 · 0 评论 -
回文、公共字符串链表
2021.3.185. 最长回文子串 class Solution { public String longestPalindrome(String s) { String res = ""; for (int i = 0; i < s.length(); i++) { //长度为奇数 String s1 = palindrome(s, i, i);原创 2021-03-18 16:12:55 · 73 阅读 · 0 评论 -
区间问题
2021.3.17方法:排序画图1288. 删除被覆盖区间 class Solution { public int removeCoveredIntervals(int[][] intervals) { Arrays.sort(intervals, (a, b) -> { if (a[0] == b[0]) { return b[1] - a[1];原创 2021-03-17 22:36:07 · 79 阅读 · 0 评论 -
打家劫舍
2021.3.17198. 打家劫舍 class Solution { private int[] memo; public int rob(int[] nums) { memo = new int[nums.length]; Arrays.fill(memo, -1); return dp(nums, 0); } private int dp(int[]原创 2021-03-17 20:57:36 · 64 阅读 · 0 评论 -
滑动窗口算法
2021.3.16567. 字符串的排列 class Solution { public boolean checkInclusion(String s1, String s2) { Map<Character, Integer> need = new HashMap<>(); for (char c : s1.toCharArray()) { need.put(c, need原创 2021-03-16 21:28:44 · 60 阅读 · 0 评论 -
股票买卖问题
2021.3.16121. 买卖股票的最佳时机 class Solution { public int maxProfit(int[] prices) { int n = prices.length; //base case int dp_i_0 = 0, dp_i_1 = Integer.MIN_VALUE; for (int i = 0; i < n; i++) {原创 2021-03-16 21:23:19 · 71 阅读 · 0 评论 -
树
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNod...原创 2021-03-14 22:37:49 · 184 阅读 · 4 评论