随笔分类 -  LeetCode刷题笔记

摘要:/* public class TreeLinkNode { int val; TreeLinkNode left = null; TreeLinkNode right = null; TreeLinkNode next = null; TreeLinkNode(int val) { this.va 阅读全文
posted @ 2020-10-22 15:37 dlooooo 阅读(77) 评论(0) 推荐(0)
摘要:class Solution { public int reversePairs(int[] nums) { int left = 0; int right = nums.length-1; int cnt=0; int[] tmp = new int[nums.length]; Arrays.fi 阅读全文
posted @ 2020-10-17 16:40 dlooooo 阅读(129) 评论(0) 推荐(0)
摘要:class Solution { public int findPeakElement(int[] nums) { if(nums.length==1||nums[0]>nums[1]){ return 0; } if(nums[nums.length-1]>nums[nums.length-2]) 阅读全文
posted @ 2020-10-17 15:44 dlooooo 阅读(77) 评论(0) 推荐(0)
摘要:class Solution { public int maxProfit(int[] prices) { int len = prices.length; int res = 0; int i = 0; while(i < len - 1){ while(i < len - 1 && prices 阅读全文
posted @ 2020-10-17 15:23 dlooooo 阅读(74) 评论(0) 推荐(0)
摘要:class Solution { public int twoCitySchedCost(int[][] costs) { int len = costs.length; int t = len/2; Arrays.sort(costs,(a,b)->{return a[0]-a[1]-(b[0]- 阅读全文
posted @ 2020-10-13 13:51 dlooooo 阅读(61) 评论(0) 推荐(0)
摘要:class Solution { public int coinChange(int[] coins, int amount) { Arrays.sort(coins); int[] dp = new int[amount+1]; Arrays.fill(dp,amount+1); dp[0] = 阅读全文
posted @ 2020-10-10 10:11 dlooooo 阅读(88) 评论(0) 推荐(0)
摘要:class Solution { public ListNode reverse(ListNode a,ListNode b){ a.next = b.next; b.next = null; b.next = a; return b; } public ListNode swapPairs(Lis 阅读全文
posted @ 2020-10-09 10:07 dlooooo 阅读(107) 评论(0) 推荐(0)
摘要:class Solution { public TreeNode Build(int[]nums,int left,int right){ if(left>right){ return null; } int mid = (left+right)>>1; TreeNode t = new TreeN 阅读全文
posted @ 2020-10-09 09:55 dlooooo 阅读(106) 评论(0) 推荐(0)
摘要:class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int[] res = new int[m+n+1]; int l1 = 0; int l2 = 0; int i=0; while((l1<m) 阅读全文
posted @ 2020-10-07 09:14 dlooooo 阅读(159) 评论(0) 推荐(0)
摘要:class Solution { public int longestConsecutive(int[] nums) { if(nums==null){ return 0; } Arrays.sort(nums); PriorityQueue<Integer> que = new PriorityQ 阅读全文
posted @ 2020-10-07 09:06 dlooooo 阅读(88) 评论(0) 推荐(0)
摘要:class Solution { public int longestConsecutive(int[] nums) { if(nums==null){ return 0; } Arrays.sort(nums); PriorityQueue<Integer> que = new PriorityQ 阅读全文
posted @ 2020-10-07 08:45 dlooooo 阅读(126) 评论(0) 推荐(0)
摘要:class Solution { public void dfs(List<List<Integer>>res,TreeNode t,int sum,LinkedList<Integer>que){ if((sum-t.val)==0&&(t.left==null&&t.right==null)){ 阅读全文
posted @ 2020-10-06 09:12 dlooooo 阅读(144) 评论(0) 推荐(0)
摘要:class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> res = new LinkedList<>(); Deque<TreeNode> stack = new LinkedLis 阅读全文
posted @ 2020-10-06 08:20 dlooooo 阅读(86) 评论(0) 推荐(0)
摘要:class Solution { public List<Integer> inorderTraversal(TreeNode root) { Deque<TreeNode> stack = new LinkedList<>(); TreeNode t = root; List<Integer> r 阅读全文
posted @ 2020-10-06 08:15 dlooooo 阅读(90) 评论(0) 推荐(0)
摘要:class Solution { public List<Integer> postorderTraversal(TreeNode root) { List<Integer> res = new LinkedList<>(); Deque<TreeNode> stack = new LinkedLi 阅读全文
posted @ 2020-10-05 20:00 dlooooo 阅读(108) 评论(0) 推荐(0)
摘要:public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA==null||headB==null){ return null; } ListNode a 阅读全文
posted @ 2020-10-05 10:20 dlooooo 阅读(76) 评论(0) 推荐(0)
摘要:class Solution { public String addStrings(String num1, String num2) { int mlen = Math.min(num1.length(),num2.length())-1; String res = new String(); i 阅读全文
posted @ 2020-10-05 10:12 dlooooo 阅读(118) 评论(0) 推荐(0)
摘要:class Solution { public ListNode Find(ListNode head){ ListNode slow = head; ListNode quick = head; while(slow!=null&&quick!=null){ if(quick.next!=null 阅读全文
posted @ 2020-10-05 09:50 dlooooo 阅读(85) 评论(0) 推荐(0)
摘要:class MinStack { Deque<Integer> stack; Deque<Integer> min_stack; /** initialize your data structure here. */ public MinStack() { stack = new LinkedLis 阅读全文
posted @ 2020-10-04 08:58 dlooooo 阅读(72) 评论(0) 推荐(0)
摘要:class Solution { private TreeNode res = null; public boolean dfs(TreeNode root,TreeNode p,TreeNode q){ if(root==null){ return false; } boolean lchild 阅读全文
posted @ 2020-10-04 08:46 dlooooo 阅读(79) 评论(0) 推荐(0)