随笔分类 -  LeetCode刷题笔记

摘要:class Solution { public void HeapAdjust(int[] nums,int s,int d){ //int t = nums[s]; int k = s; for(int i=s*2+1;i<=d;i=i*2+1){ if((i+1<=d)&&nums[i]<num 阅读全文
posted @ 2020-10-04 08:24 dlooooo 阅读(151) 评论(0) 推荐(0)
摘要:我写的bug也太多了 class Solution { public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> res = new LinkedList<List<Integer>>(); if 阅读全文
posted @ 2020-10-03 09:55 dlooooo 阅读(183) 评论(0) 推荐(0)
摘要:本来想自己写个二分查找,想了想好累。。。还是遍历吧 class Solution { public TreeNode binaryTree(int[]preorder,int[]inorder,int start,int end,int begin,int fin) { if(start>end){ 阅读全文
posted @ 2020-10-03 09:32 dlooooo 阅读(173) 评论(0) 推荐(0)
摘要:class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { if(l1==null){ return l2; } if(l2==null){ return l1; } int t=0; ListNode res 阅读全文
posted @ 2020-10-03 08:40 dlooooo 阅读(111) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ publi 阅读全文
posted @ 2020-10-02 09:03 dlooooo 阅读(156) 评论(0) 推荐(0)
摘要:class Solution { public int binary_search(int[]nums,int left,int right,int target){ int mid=0; while(left<=right){ mid = (left+right)/2; if(nums[mid]> 阅读全文
posted @ 2020-10-02 08:53 dlooooo 阅读(160) 评论(0) 推荐(0)
摘要:class Solution { public int maxProfit(int[] prices) { int res=0; int MinPrice = Integer.MAX_VALUE; int len = prices.length-1; for(int i=0;i<=len;i++){ 阅读全文
posted @ 2020-10-02 08:22 dlooooo 阅读(117) 评论(0) 推荐(0)
摘要:板子题做多了的弊病,条件总是考虑不全。再接再厉!下次遇到一维数组扫描的,直接双指针再说,不犹豫了。 class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> res = new Arr 阅读全文
posted @ 2020-10-01 20:09 dlooooo 阅读(167) 评论(0) 推荐(0)
摘要:也就是LeetCode25里用到了反转子链表的方法,只不过这次直接反转整个链表。头插法就能解决了 class Solution { public ListNode reverseList(ListNode head) { ListNode t = new ListNode(-1); t.next = 阅读全文
posted @ 2020-09-30 17:43 dlooooo 阅读(60) 评论(0) 推荐(0)
摘要:想了想,毕竟以后可能还是敲Java得多,不如做题也改成Java好了。结果一做题,C++的惯性思维还是改不掉。在指针和对象引用互相转换,真是吐了。题目倒是不难,ac了之后看了看题解,再稍微改了改。 不得不说,以后还是用Java写好了。免得把这些有的没的带到工作中。 既然是翻转,就还是用头插法好了。其他 阅读全文
posted @ 2020-09-30 17:36 dlooooo 阅读(114) 评论(0) 推荐(0)
摘要:之前其他oj上刷题刷习惯了,看到题目总是想得复杂了些。第一次刷leetcode,看到题目,差点以为一来就得深搜或者动态规划了,大半年没敲过代码,心里难免是绝望的。读完题发现没那么复杂,可能不是最优解,但也算比较容易ac了。 思路也很简单,用双指针表示滑窗。滑窗不停向后扩展,且滑窗大小始终保持此前最大 阅读全文
posted @ 2020-09-30 15:45 dlooooo 阅读(117) 评论(0) 推荐(0)