![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
fb
Belle唯唯
这个作者很懒,什么都没留下…
展开
-
[leetcode]621. Task Scheduler
https://leetcode.com/problems/task-scheduler/discuss/104500/Java-O(n)-time-O(1)-space-1-pass-no-sorting-solution-with-detailed-explanationclass Solution { public int leastInterval(char[] tasks, i...原创 2019-10-13 04:29:34 · 105 阅读 · 0 评论 -
[leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List
中序遍历的变形/*// Definition for a Node.class Node { public int val; public Node left; public Node right; public Node() {} public Node(int _val,Node _left,Node _right) { val...原创 2019-10-02 12:30:51 · 105 阅读 · 0 评论 -
[leetcode] 708. Insert into a Cyclic Sorted List
/*// Definition for a Node.class Node { public int val; public Node next; public Node() {} public Node(int _val,Node _next) { val = _val; next = _next; }};*/...原创 2019-10-02 11:05:47 · 197 阅读 · 0 评论 -
QuickSort和QuickSelect
class Solution { public int[] sortArray(int[] nums) { quickSort(nums,0,nums.length-1); return nums; } public void quickSort(int[] nums, int l,int r){ ...原创 2019-09-29 05:44:45 · 221 阅读 · 0 评论 -
MergeSort
class Solution { public int[] sortArray(int[] nums) { int[] temp = new int[nums.length]; mergeSort(nums,0,nums.length-1,temp); return nums; } ...原创 2019-09-29 05:40:53 · 108 阅读 · 1 评论 -
[leetcode]253. Meeting Rooms II
class Solution { public int minMeetingRooms(int[][] intervals) { if(intervals == null || intervals.length == 0) return 0; PriorityQueue<Integer> pq = new PriorityQueue<>...原创 2019-09-23 12:56:12 · 94 阅读 · 0 评论 -
[leetcode]301. Remove Invalid Parentheses
class Solution { public List<String> removeInvalidParentheses(String s) { int left = 0; int right = 0; for(int i = 0; i < s.length(); i++){ if(s.charAt...原创 2019-09-23 05:10:04 · 98 阅读 · 0 评论 -
[leetcode]349. Intersection of Two Arrays
Solution 1: 二分法 nlognset去除重复class Solution { public int[] intersection(int[] nums1, int[] nums2) { HashSet<Integer> set = new HashSet<Integer>(); Arrays.sort(nums2);...原创 2019-09-20 05:11:45 · 93 阅读 · 0 评论 -
[leetcode]973. K Closest Points to Origin
solution 1: quick select时间复杂度 o(n)空间O(n)class Solution { public int[][] kClosest(int[][] points, int K) { quick(points, 0,points.length-1, K); return Arrays.copyOf...原创 2019-09-08 11:30:58 · 216 阅读 · 0 评论 -
[leetcode]98. Validate Binary Search Tree
Solution 1 : recursive这一题要特别注意corner case。lower和upper用Integer.MIN_VALUE 和 Integer.MAX_VALUE是过不了的。因为BST规定: left.val<root.val && right.val>root.val。如果root正好是Integer.MAX_VALUE,会被误判为false...原创 2019-09-05 23:33:42 · 134 阅读 · 0 评论