Find the Duplicate Number
LeetCode https://leetcode.cn/problems/find-the-duplicate-number/ Binary search class Solution { public int findDuplicate(int[] nums) { int n = nums.length; int l = 1, r = n - ...
LeetCode https://leetcode.cn/problems/find-the-duplicate-number/ Binary search class Solution { public int findDuplicate(int[] nums) { int n = nums.length; int l = 1, r = n - ...
LeetCode https://leetcode.cn/problems/find-median-from-data-stream/
LeetCode https://leetcode.cn/problems/top-k-frequent-elements/ class Solution { public int[] topKFrequent(int[] nums, int k) { Map<Integer, Integer> freq = new HashMap<>();...
LeetCode https://leetcode.cn/problems/kth-largest-element-in-an-array/ class Solution { public int findKthLargest(int[] nums, int k) { Queue<Integer> maxHeap = new PriorityQueue&...
LeetCode https://leetcode.cn/problems/reverse-nodes-in-k-group/ Recursive /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNod...
LeetCode https://leetcode.cn/problems/sort-list/ /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int...
LeetCode https://leetcode.cn/problems/copy-list-with-random-pointer/ Solution 1: HashMap Idea: Build mapping between node in the original list and the corresponding node in the new list Two poin...
LeetCode https://leetcode.cn/problems/search-insert-position/ class Solution { public int searchInsert(int[] nums, int target) { // if (nums.length <= 1) { // return 1; ...
LeetCode https://leetcode.cn/problems/min-stack/ code class MinStack { public MinStack() { } public void push(int val) { } public void pop() { } publ...