摘要:
题目链接:https://leetcode-cn.com/problems/remove-duplicates-from-sorted-list-ii/ ##题解1:用Map记录哪个项是没有重复的 /** * Definition for singly-linked list. * public c 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/surrounded-regions/ ##官方题解 从四个边界的O出发进行深度搜索,将可以走通的路标为A,之后将A换为O,之后将不是A换过来的O置为X证明走不通。 class Solution { int n, m; pu 阅读全文
摘要:
题目链接:https://leetcode-cn.com/problems/count-binary-substrings/ ##暴力超时了的代码:90个样例只过了37个 class Solution { public int countBinarySubstrings(String s) { in 阅读全文
摘要:
##工厂模式 工厂模式是类创建模式的一种,通常是工厂类来根据传入参数的不同来创建不同类的实例,工厂类创建类的实例,这些类通常是有一个公共的父类。 下面的这张图基本展示了这种关系 ##Dataformat创建 ##简单工厂模式实例 public class SimpleFactory { public 阅读全文
摘要:
破环: 3种情况: 1、选头不选尾 2、选尾不选头 3、不选头和尾 题目变化成打家劫舍1版本了,设置两个dp,一个舍去头一个舍去尾,之后比较两者最大值即可。 class Solution { public int rob(int[] nums) { int n = nums.length; if ( 阅读全文
摘要:
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家打劫的 阅读全文
摘要:
思路:用容量为K的最小堆优先队列,把链表的头结点都放进去,然后出队当前优先队列中最小的,挂上链表,,然后让出队的那个节点的下一个入队,再出队当前优先队列中最小的,直到优先队列为空。 /** * Definition for singly-linked list. * public class Lis 阅读全文
摘要:
##时间复杂度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 阅读全文