自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(42)
  • 收藏
  • 关注

原创 312-戳气球

1.自顶向下的递归+记忆化搜索class Solution { int[] val; int[][] rec; public int maxCoins(int[] nums) { /** 自顶向下的递归 + 记忆化搜索 思想:逆向思维! 将删除的过程反过来,每次向数组中添加元素并计算每次获得的硬币数 */ int n = nums.length; //给

2021-11-16 11:02:15 479

原创 239.滑动窗口最大值

1.优先级队列class Solution { public int[] maxSlidingWindow(int[] nums, int k) { //优先级队列 int n = nums.length; PriorityQueue<int[]> pq = new PriorityQueue<int[]>(new Comparator<int[]>() { public int compa

2021-11-05 12:36:47 368

原创 并查集(399,990,547、1631)

如果一个问题具有传递性,则考虑使用并查集!399.除法求值399-除法求值class Solution { public double[] calcEquation(List<List<String>> equations, double[] values, List<List<String>> queries) { //并查集!! //如果一个问题具有传递性,则考虑使用并查集!! int equa

2021-10-13 21:58:46 84

原创 560-和为k的子数组(前缀和)

class Solution { public int subarraySum(int[] nums, int k) { //前缀和 Map<Integer, Integer> map = new HashMap<>(); map.put(0, 1);//map保存前i项和的值以及出现的次数 int ans = 0, pre = 0; for(int i = 0;i < nums.lengt

2021-10-10 14:31:05 51

原创 581-最短无序连续子数组

判断数组元素是否无序的方法!class Solution { public int findUnsortedSubarray(int[] nums) { /*思想:从左向右遍历,若当前数比前面的最大值小则表明该数需要重排,以此可以找到需要重排的最右端 同理,从右向左遍历,若当前数比之前的最小值大则表明该数需要重排,以此可以找到需要重排的最左端 */ int n = nums.length; int ma

2021-10-06 15:40:32 50

原创 完全背包问题(279,322,518)

322 零钱兑换class Solution { public int coinChange(int[] coins, int amount) { //完全背包问题 // int n = coins.length, max = amount+1; // int[][] dp = new int[n+1][max];//dp[i][j]表示前i个硬币组成j的最少硬币数 // //初始化 // Arrays.fill(d

2021-09-29 11:49:42 47

原创 servlet

关于servlet对象生命周期1.什么是生命周期 生命周期表示一个java对象从创建到被销毁经理的所有过程。2.Servlet对象的生命周期谁来管理?程序员可以干涉吗? Servlet对象的创建,方法调用以及对象的销毁整个过程都是由web容器来管理的。程序员无权干涉。3.默认情况下,Servlet对象在web服务器启动阶段不会被实例化。4.描述servlet生命周期 (1) 用户在浏览器地址栏上输入URL:http://ip:端口号//请求路径 (2) web容器截取请求路径并在容器上下文中

2021-09-22 16:55:42 52

原创 01背包问题(416、494、474、1049)

01背包问题---->动态规划class Solution { public boolean canPartition(int[] nums) { //动态规划(二维!) 01背包问题! int sum = 0, n = nums.length; for(int num : nums){ sum += num; } if(sum % 2 == 1) return f

2021-09-17 11:50:12 58

原创 406-根据身高重建队列

从低到高考虑先放的对后放的没有影响,因此放的时候只需要满足前面还有k个空位class Solution { public int[][] reconstructQueue(int[][] people) { //核心思想:按照h升序k降序排后再放入队列,要实现先放的对后放的没有影响 int n = people.length; int[][] ans = new int[n][2]; Queue<int[]> queue

2021-09-14 11:29:04 42

原创 java反射机制

1.基本概念反射机制提供的类java.lang.Class;//类java.lang.reflect.Constructor;//构造器java.lang.reflect.Field;//属性java.lang.reflect.Method;//方法java.lang.reflect.Modifier; //修饰符2.作用<1>反编译:.class—>.java<2>通过反射机制访问java对象的属性方法等3.获取类对象的三种方式User u = new

2021-09-11 14:22:06 48

原创 240-搜索二维矩阵Ⅱ

将矩阵看作二叉搜索树!!class Solution { public boolean searchMatrix(int[][] matrix, int target) { //将矩阵看作二叉搜索树 int m = matrix.length, n = matrix[0].length; //从右上角开始搜索(也可以从左下角开始) int row = 0, col = n-1; while(row < m &am

2021-09-10 10:55:40 40

原创 461-汉明距离

1.内置位计数函数class Solution { public int hammingDistance(int x, int y) { //内置位计数函数 return Integer.bitCount(x ^ y); }}2.Brian Kernighan 算法class Solution { public int hammingDistance(int x, int y) { //Brian Kernighan 算法 每

2021-09-10 09:19:32 47

原创 221-最大正方形

动态规划当前正方形的边长由其左方、左上方、上方的正方形边长决定!!class Solution { public int maximalSquare(char[][] matrix) { //动态规划 dp[i][j]表示以m[i][j]为右下角的正方形的边长 int row = matrix.length, col = matrix[0].length; int[][] dp = new int[row][col]; int ma

2021-09-09 11:37:20 36

原创 Spring框架

1

2021-09-08 21:43:09 40

原创 207-课程表

拓扑排序!!class Solution { public boolean canFinish(int numCourses, int[][] prerequisites) { //拓扑排序判断有向无环图!!! List<List<Integer>> edges = new ArrayList<>();//邻接表 for(int i = 0;i < numCourses;i++){ e

2021-09-08 11:08:28 45

原创 85-最大矩形

单调栈class Solution { public int maximalRectangle(char[][] matrix) { //单调栈 结合第84题! int row = matrix.length, col = 0; if(row > 0) col = matrix[0].length; int[][] dp = new int[row][col]; //dp[i][j]记录第

2021-09-04 10:48:08 47

原创 338-比特位计数

动态规划class Solution { public int[] countBits(int n) { //动态规划 找做高有效位 int[] dp = new int[n+1]; dp[0] = 0; int highBit = 0;//记录最近的2的整数幂 for(int i = 1;i < n+1;i++){ if((i & (i-1)) == 0){//满足则说明i是2的

2021-09-03 10:52:37 48

原创 128-最长连续序列

哈希表 (经典空间换时间)class Solution { public int longestConsecutive(int[] nums) { //哈希表!! 对时间有要求就要用空间来换! int ans = 0; HashSet<Integer> set = new HashSet<>(); for(int num : nums){ set.add(num); }

2021-09-02 10:59:17 50

原创 72-编辑距离

1.自顶向下的递归超时了,因为递归时进行了很多重复计算class Solution { public int minDistance(String word1, String word2) { /* 操作可以简化为以下3种: 1.对A进行插入 2.对A进行删除 3.对A进行替换 */ //自顶向下的递归 超时。。 //每次比较最后一个字符 if(word

2021-09-01 15:47:23 40

原创 JDBC。

1.JDBC的本质JDBC时SUN公司提供的一套接口

2021-08-31 20:53:55 62

原创 买股票(Ⅰ,Ⅱ,Ⅲ,Ⅳ,冷冻期,手续费)

121.买卖股票的最佳时机class Solution { public int maxProfit(int[] prices) { //一次遍历 int minPrice = prices[0]; int maxProfit = 0; for(int i = 1;i < prices.length;i++){ if(prices[i] < minPrice) min

2021-08-26 13:50:11 57

原创 子集(Ⅰ,Ⅱ)

78.子集回溯法class Solution { List<List<Integer>> ans = new ArrayList<>(); List<Integer> ls = new ArrayList<>(); public List<List<Integer>> subsets(int[] nums) { //回溯法 f(nums, 0); r

2021-08-24 12:24:01 40

原创 84-柱状图的最大矩形

单调栈class Solution { public int largestRectangleArea(int[] heights) { //核心思想:以h[i]为高的矩形的宽等于i左右两边第一个小于h[i]之间的距离 //单调栈 int len = heights.length, area = 0; Deque<Integer> st = new LinkedList<>(); //添加哨兵

2021-08-23 12:05:20 31

原创 区间合并(56,57)

56.合并区间class Solution { public int[][] merge(int[][] intervals) { //先排序! Arrays.sort(intervals,new Comparator<int[]>(){//按intervals[i][0]从小到大排! public int compare(int[] interval1, int[] interval2){ ret

2021-08-20 15:15:19 33

原创 单调栈(42、84、739)

核心思想:i处的积水等于左右峰值的最小值减去自身!1.暴力法class Solution { public int trap(int[] height) { //核心思想:i处的积水等于左右峰值的最小值减去自身!!! //暴力法 int n = height.length; int ans = 0; for(int i = 1;i < n-1;i++){ //对于每一个元素,寻找它的左右

2021-08-19 13:57:17 28

原创 Mysql习题

数据库:bjpowernode.sql1.找出每个部门的最高薪资的员工select t.deptno, e.ename, t.sal from emp e join (select deptno, max(sal) sal from emp group by deptno) t on e.sal = t.sal;2.哪些人的薪资在部门平均水平之上select e.deptno, e.ename, e.sal from emp e join (select deptno, avg(sal) avgs

2021-08-18 17:05:02 71

原创 41-缺失的第一个正数

要求:时间O(n) 空间O(1)1.置换class Solution { public int firstMissingPositive(int[] nums) { //置换 将x换到x-1的位置上 [1,2,3,4,...] int n = nums.length; for(int i = 0;i < n;i++){ while(nums[i] > 0 && nums[i] < n+1 &

2021-08-17 15:33:46 38

原创 17-电话号码的字母组合

回溯法class Solution { public List<String> letterCombinations(String digits) { //回溯法 List<String> ans = new ArrayList<>(); if(digits.length() == 0) return ans; String[] strs = {"abc", "def", "

2021-08-16 12:20:39 33

原创 回文串(5,131,132)

1.动态规划class Solution { public String longestPalindrome(String s) { //难!! //动态规划 int n = s.length(); boolean[][] dp = new boolean[n][n];//dp[i][j]表示s[i...j]是回文串!!! int start = 0, maxLen = 1; char[] str =

2021-08-14 12:50:02 21

原创 滑动窗口(3, 438,76)

滑动窗口(双指针)class Solution { public int lengthOfLongestSubstring(String s) { //滑动窗口(双指针!) int n = s.length(); Map<Character, Integer> map = new HashMap<>(); if(n == 0) return 0; int left = 0, ans = 1;

2021-08-13 12:37:46 40

原创 x数之和(1、15、16、18)

1.两数之和哈希表class Solution { public int[] twoSum(int[] nums, int target) { Map<Integer, Integer> map = new HashMap<>();//{num[i]:i} for(int i = 0;i < nums.length;i++){ if(map.containsKey(target-nums[i])){

2021-08-11 14:18:44 88

原创 94-二叉树中序遍历、538-反向中序遍历、后序遍历(非递归!)

1.递归class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> ans = new ArrayList<>(); dfs(ans, root); return ans; } public void dfs(List<Integer> ans, TreeNode root){

2021-08-10 16:14:19 155

原创 组合总数(Ⅰ、Ⅱ、Ⅲ、Ⅳ)

组合总数Ⅰ组合总数Ⅱ组合总数Ⅲ回溯法class Solution { //回溯法 List<List<Integer>> ans = new ArrayList<>(); List<Integer> ls = new ArrayList<>(); public List<List<Integer>> combinationSum3(int k, int n) { f(1

2021-08-09 11:36:55 41

原创 137-只出现一次的数字Ⅱ

二进制!!class Solution { public int singleNumber(int[] nums) { //二进制yyds!! //对于每一位的二进制的1和0累加起来必然是3N或者3N+1,为3N代表目标值在这一位没贡献,3N+1代表目标值在这一位有贡献(=1),然后将所有有贡献的位|起来就是结果 int ans = 0; for(int i = 0;i < 32;i++){//把每个数拆成32位逐位分析

2021-08-06 20:37:57 41

原创 Mysql常用命令

1.查看有哪些数据库show databases;2.选择使用数据库use database3.创建数据库create database mydatabase;4.导入数据source 数据库所在路径;5.查看某数据库下有哪些表show tables;6.查看表中数据select * from 表名;7.查看表结构desc 表名;...

2021-08-02 17:38:36 121

原创 91-解码方法

动态规划class Solution { public int numDecodings(String s) { //动规 int n = s.length(); int[] f = new int[n]; f[0] = s.charAt(0) == '0' ? 0 : 1; for(int i = 1;i < n;i++){ if(s.charAt(i) == '0'){

2021-08-01 21:46:55 77

原创 238-除自身以外数组的乘积

左右乘积列表class Solution { public int[] productExceptSelf(int[] nums) { //O(1)空间,将L用output代替,R使用动态数组即可 int n = nums.length; int[] output = new int[n]; output[0] = 1; int R = 1; for(int i = 1;i < n;i++){

2021-07-28 11:15:43 32

原创 347-前k个高频元素

对字典按value排序class Solution { public int[] topKFrequent(int[] nums, int k) { //对map按value排序 Map<Integer, Integer> map = new HashMap<>(); int[] ans = new int[k]; for(int key : nums){ int val = map.g

2021-07-26 19:40:59 25

原创 309-买卖股票带冷冻期

动态规划class Solution { public int maxProfit(int[] prices) { int n = prices.length; int dp0 = 0;//dp[i][0]不持有股票且不处于冷冻状态时的收益 int dp1 = -prices[0];//dp[i][1]持有股票时的收益 int dp2 = 0;//dp[i][2]表示处于冷冻状态,即当天卖出时的收益 for(int i

2021-07-23 09:33:26 32

原创 SQL常用命令

SQL语句分类:1.数据查询语句DQL: select...2.数据操作语句子DML(操作表中数据): insert 增 delete 删 update 改3.数据定义语句DDL(操作表结构): create 新建 drop 删除 alert 修改

2021-07-22 21:21:15 38

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除