上一页 1 2 3 4 5 6 7 ··· 36 下一页
摘要: 题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ ##题解1:用Map记录哪个项是没有重复的 /** * Definition for singly-linked list. * public c 阅读全文
posted @ 2020-08-20 21:31 浅滩浅 阅读(174) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/surrounded-regions/ ##官方题解 从四个边界的O出发进行深度搜索,将可以走通的路标为A,之后将A换为O,之后将不是A换过来的O置为X证明走不通。 class Solution { int n, m; pu 阅读全文
posted @ 2020-08-17 16:09 浅滩浅 阅读(79) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode-cn.com/problems/count-binary-substrings/ ##暴力超时了的代码:90个样例只过了37个 class Solution { public int countBinarySubstrings(String s) { in 阅读全文
posted @ 2020-08-17 14:00 浅滩浅 阅读(130) 评论(0) 推荐(0)
摘要: ##工厂模式 工厂模式是类创建模式的一种,通常是工厂类来根据传入参数的不同来创建不同类的实例,工厂类创建类的实例,这些类通常是有一个公共的父类。 下面的这张图基本展示了这种关系 ##Dataformat创建 ##简单工厂模式实例 public class SimpleFactory { public 阅读全文
posted @ 2020-08-07 20:26 浅滩浅 阅读(126) 评论(0) 推荐(0)
摘要: 破环: 3种情况: 1、选头不选尾 2、选尾不选头 3、不选头和尾 题目变化成打家劫舍1版本了,设置两个dp,一个舍去头一个舍去尾,之后比较两者最大值即可。 class Solution { public int rob(int[] nums) { int n = nums.length; if ( 阅读全文
posted @ 2020-08-07 19:01 浅滩浅 阅读(66) 评论(0) 推荐(0)
摘要: class Solution { public int rob(int[] nums) { int n = nums.length; if (n == 0) return 0; if (n == 1) return nums[0]; int[] dp = new int[n];//截止到第i家打劫的 阅读全文
posted @ 2020-08-07 18:41 浅滩浅 阅读(156) 评论(0) 推荐(0)
摘要: 二叉树的遍历 前序遍历: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNo 阅读全文
posted @ 2020-08-07 18:21 浅滩浅 阅读(116) 评论(0) 推荐(0)
摘要: 思路:用容量为K的最小堆优先队列,把链表的头结点都放进去,然后出队当前优先队列中最小的,挂上链表,,然后让出队的那个节点的下一个入队,再出队当前优先队列中最小的,直到优先队列为空。 /** * Definition for singly-linked list. * public class Lis 阅读全文
posted @ 2020-08-03 19:09 浅滩浅 阅读(90) 评论(0) 推荐(0)
摘要: 这道题不是循环数组用的是栈存储的是数组的值不是下标,如果是循环数组用值会出现无法确定结果要赋值到哪个位置 class Solution { public int[] nextGreaterElement(int[] nums1, int[] nums2) { //不是循环数组 int[] res = 阅读全文
posted @ 2020-08-02 21:18 浅滩浅 阅读(116) 评论(0) 推荐(0)
摘要: ##时间复杂度O(n^2) class Solution { public int[] nextGreaterElements(int[] nums) { int[] res = new int[nums.length]; int top = 0; for(int i=0;i<nums.length 阅读全文
posted @ 2020-08-02 20:55 浅滩浅 阅读(72) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 ··· 36 下一页