随笔分类 - LeetCode刷题笔记
摘要:/* public class TreeLinkNode { int val; TreeLinkNode left = null; TreeLinkNode right = null; TreeLinkNode next = null; TreeLinkNode(int val) { this.va
阅读全文
摘要: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
阅读全文
摘要: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])
阅读全文
摘要: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
阅读全文
摘要: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]-
阅读全文
摘要: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] =
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文
摘要: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)
阅读全文
摘要:class Solution { public int longestConsecutive(int[] nums) { if(nums==null){ return 0; } Arrays.sort(nums); PriorityQueue<Integer> que = new PriorityQ
阅读全文
摘要:class Solution { public int longestConsecutive(int[] nums) { if(nums==null){ return 0; } Arrays.sort(nums); PriorityQueue<Integer> que = new PriorityQ
阅读全文
摘要: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)){
阅读全文
摘要:class Solution { public List<Integer> preorderTraversal(TreeNode root) { List<Integer> res = new LinkedList<>(); Deque<TreeNode> stack = new LinkedLis
阅读全文
摘要:class Solution { public List<Integer> inorderTraversal(TreeNode root) { Deque<TreeNode> stack = new LinkedList<>(); TreeNode t = root; List<Integer> r
阅读全文
摘要:class Solution { public List<Integer> postorderTraversal(TreeNode root) { List<Integer> res = new LinkedList<>(); Deque<TreeNode> stack = new LinkedLi
阅读全文
摘要:public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA==null||headB==null){ return null; } ListNode a
阅读全文
摘要:class Solution { public String addStrings(String num1, String num2) { int mlen = Math.min(num1.length(),num2.length())-1; String res = new String(); i
阅读全文
摘要:class Solution { public ListNode Find(ListNode head){ ListNode slow = head; ListNode quick = head; while(slow!=null&&quick!=null){ if(quick.next!=null
阅读全文
摘要:class MinStack { Deque<Integer> stack; Deque<Integer> min_stack; /** initialize your data structure here. */ public MinStack() { stack = new LinkedLis
阅读全文
摘要:class Solution { private TreeNode res = null; public boolean dfs(TreeNode root,TreeNode p,TreeNode q){ if(root==null){ return false; } boolean lchild
阅读全文
浙公网安备 33010602011771号