自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 mybatis踩坑

原因是因为传递一个 List 实例或者数组作为参数对象传给 MyBatis时,MyBatis 会自动将它包装在一个 Map 中,用名称作为 key,List 实例将会以 “list” 作为 key,而数组实例将会以 “array” 作为 key。foreach批量插入数据时,collections是传入的参数list,item是list中的元素类型,separator表示分隔符类型。这时候会报错,因为mybatis不知道emp是什么,错误地以为emp是Emp中的属性。

2022-08-20 22:31:49 291 1

原创 Day03_Java&Guava

Guava基础

2022-07-15 10:04:56 333

原创 day02-Git

Git学习

2022-07-12 19:25:16 123

原创 word单独编辑或者删除某一页的页眉

word单独编辑或者删除某一页的页眉

2022-06-11 15:29:57 6738

原创 SQL基础

创建表CREATE TABLEIF NOT EXISTS tb_name -- 不存在才创建,存在就跳过(column_name1 data_type1 -- 列名和类型必选 [ PRIMARY KEY -- 可选的约束,主键 | FOREIGN KEY -- 外键,引用其他表的键值 | AUTO_INCREMENT -- 自增ID | COMMENT comment -- 列注释(评论) | DEFAULT default_value -- 默认值 | UNIQUE

2022-04-05 19:39:36 758

原创 8. 字符串转换整数 (atoi)

思路:依次遍历,注意前导的空格符,注意正负号以及边界条件。class Solution { public int myAtoi(String s) { int i = 0, n = s.length(); // 结果 int res = 0; // 正负数的标志位 int flag = 1; // 去除前面的空字符 while(i < n && s.charAt(.

2021-09-27 16:49:07 59

原创 46. 全排列

回溯算法的框架for 选择 in 选择列表: # 做选择 将该选择从选择列表移除 路径.add(选择) backtrack(路径, 选择列表) # 撤销选择 路径.remove(选择) 将该选择再加入选择列表class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer&g.

2021-09-22 10:00:40 54

原创 225. (一个or两个)队列实现栈

这里写目录标题两个队列一个队列两个队列思路:每次把元素push进q2,然后把q1的元素push进q2,再交换q1和q2。比如 1 2, 那么第一次q2是1, q1为空,然后交换 q1是1,q2为空第二次 q2push了2,现在是2,q1这时候是1,然后把q1push到q2,q2就变成了2 1,此时q1为空,然后再交换q1,q2,那么q1就是 2 1,q2是空class MyStack { Queue<Integer> q1; Queue<Integer&gt.

2021-08-24 21:17:48 99

原创 剑指 Offer 38. 字符串的排列

class Solution { List<String> res = new ArrayList<>(); public String[] permutation(String s) { char[] arr = s.toCharArray(); Arrays.sort(arr); backtarcking(arr, new boolean[arr.length], new StringBuilder()); .

2021-08-24 19:33:38 59

原创 牛客OJ在线编程常见输入输出练习

这里写目录标题开始1.计算a+b(1)2.计算a+b(2)3.计算a+b(3)4.计算a+b(4)开始牛客变成一定要先导包,然后写一个Main类,然后写main方法,注意main方法的参数是String[] argsimport java.util.*;public class Main{ public static void main(String[] args){ }}1.计算a+b(1)注意:当没说输出多少组数据的时候,也就是不知道循环次数的时候,就可以用sc.hasN

2021-08-21 14:49:39 331

原创 岛屿问题总结

这里写目录标题树和网格的DFS模板200. 岛屿数量695. 岛屿的最大面积树和网格的DFS模板二叉树的 DFS 有两个要素:「访问相邻结点」和「判断 base case」访问相邻结点:递归访问左右子树判断 base case:一般来说,二叉树遍历的 base case 是 root == null。这样一个条件判断其实有两个含义:一方面,这表示 root 指向的子树为空,不需要再往下遍历了。另一方面,在 root == null 的时候及时返回,可以让后面的 root.left 和 root.ri

2021-08-19 11:56:58 127

原创 202. 快乐数

class Solution {// 用set判断该数是否出现过 public boolean isHappy1(int n) { Set<Integer> set = new HashSet<>(); while(n != 1 && !set.contains(n)){ set.add(n); n = getNext(n); } return .

2021-08-10 11:19:26 67

原创 287. 寻找重复数

class Solution { public int findDuplicate(int[] nums) { int n = nums.length; int l = 1, r = n - 1; while(l < r){ int count = 0; int mid = (l + r) / 2; for(int i = 0; i < n; i++){ ..

2021-08-10 10:59:51 58

原创 279. 完全平方数

思路:BFS,每一次是原数字减去了一个平方数,直到出现第一个0,此时走过的层数就是最小数量。比如传入的数是7,那应该就是如果传入16,那应该就是16->15,12,7,0 答案就是层数,也就是1.class Solution { public int numSquares(int n) { Queue<Integer> queue=new LinkedList<>(); HashSet<Integer> visite.

2021-08-09 22:27:03 72

原创 96. 不同的二叉搜索树

思路:二叉搜索树中序遍历是递增的,现在题目给出的序列就是自增的。我们可以遍历每个数字 i,将该数字作为树根,将 1 ~ (i−1) 序列作为左子树,将 (i+1) ~ n 序列作为右子树。接着我们可以按照同样的方式递归构建左子树和右子树。class Solution { public int numTrees(int n) { if(n <= 2) return n; int[] dp = new int[n +1]; dp[0] = 1;.

2021-08-09 16:52:00 59

原创 560. 和为K的子数组

思路:暴力,三层循环,外层循环确定边界[i, j],内层循环累加求和。class Solution { public int subarraySum(int[] nums, int k) { int n = nums.length; int count = 0; for(int i = 0; i < n; i++){ for(int j = i; j < n; j++){ int .

2021-08-09 10:53:41 77

原创 86.分隔链表

思路:维护两个链表 small 和 large, small存储小于x的结点,large存储大于等于x的结点。遍历完原链表后,我们只要将 small 尾节点指向 large 头节点即可。作者:LeetCode-Solution链接:https://leetcode-cn.com/problems/partition-list/solution/fen-ge-lian-biao-by-leetcode-solution-7ade/来源:力扣(LeetCode)著作权归作者所有。商业转载请联系作者获得.

2021-08-04 19:51:21 53

原创 14. 最长公共前缀

思路:横向扫描:求两个字符串的最长公共前缀,然后一直遍历。如果某个时候最长前缀长度为0,后面的就不需要遍历了。纵向扫描:i 用来遍历第一个字符串,j 用来表示有多少个字符串class Solution { public String longestCommonPrefix(String[] strs) { if(strs == null || strs.length == 0){ return ""; } String .

2021-08-01 19:21:19 131

原创 24. 两两交换链表中的节点

思路:递归或者迭代迭代思路有两种,跟k个一组翻转链表有点像,即k = 2的时候25. K 个一组翻转链表class Solution { public ListNode reverseKGroup(ListNode head, int k) { ListNode dum = new ListNode(0, head); int len = getLen(head); ListNode pre = dum, cur = head; .

2021-08-01 14:18:48 63

原创 9. 回文数

思路:   1.转成字符串然后对比用回文串的方法    2.翻转一半字符串,然后对比。比如1221,设后半部分字符串反转后为revertedNumber,判断x == revertedNumber,12321,将321反转,判断x == revertedNumber / 10;class Solution { public boolean isPalindrome(int x) { String str = String.valueOf(x); int l =

2021-07-31 12:52:33 63

原创 7.整数反转 8. 字符串转换整数 (atoi)

这里写目录标题7.整数反转8. 字符串转换整数 (atoi)7.整数反转思路:比如123,先取出3,ans = ans * 10 + digit,得到 ans = 3, 下一次循环,取出2,ans = 3 * 10 + 2 = 32,再下一次循环取出1, ans = 32 * 10 + 1 = 321class Solution { public int reverse(int x) { int ans = 0; while(x != 0){

2021-07-31 11:19:32 44

原创 88. 合并两个有序数组

思路:  1.暴力,直接把nums2放入nums1的尾部,然后排序。class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { for (int i = 0; i != n; ++i) { nums1[m + i] = nums2[i]; } Arrays.sort(nums1); }}  2.双指针 缺点是需要新.

2021-07-25 10:32:27 44

原创 617. 合并二叉树

思路:深度优先,从根节点开始同时遍历两个二叉树,并将对应的节点进行合并。三种情况:   1.如果两个二叉树的对应节点都为空,则合并后的二叉树的对应节点也为空;   2.如果两个二叉树的对应节点只有一个为空,则合并后的二叉树的对应节点为其中的非空节点;   3.如果两个二叉树的对应节点都不为空,则合并后的二叉树的对应节点的值为两个二叉树的对应节点的值之和,此时需要显性合并两个节点。对一个节点进行合并之后,还要对该节点的左右子树分别进行合并。这是一个递归的过程class Solution { .

2021-07-15 10:32:37 120

原创 328. 奇偶链表

思路:设置两个一个奇数链表头(其实就是head),一个偶数链表头(head.next),奇连偶,偶连奇。一直循环,最后奇偶相连class Solution { public ListNode oddEvenList(ListNode head) { if(head == null) return null; ListNode odd = head; ListNode even = head.next, evenHead = head.nex.

2021-07-14 15:25:10 62

原创 628. 三个数的最大乘积

思路:1.排序后,如果数组中全是非负数,则排序后最大的三个数相乘即为最大乘积;如果全是非正数,则最大的三个数相乘同样也为最大乘积。如果数组中有正数有负数,则最大乘积既可能是三个最大正数的乘积,也可能是两个最小负数(即绝对值最大)与最大正数的乘积。   2. 在方法一中,我们实际上只要求出数组中最大的三个数以及最小的两个数,因此我们可以不用排序,用线性扫描直接得出这五个数。class Solution { public int maximumProduct(int[] nums) { .

2021-07-09 10:04:46 309

原创 470. 用 Rand7() 实现 Rand10()

公式:(randX() - 1)*Y + randY() 可以等概率的生成[1, X * Y]范围的随机数/** * The rand7() API is already defined in the parent class SolBase. * public int rand7(); * @return a random integer in the range 1 to 7 */class Solution extends SolBase { //合理利用被拒绝的随机数以减少循环.

2021-07-08 16:14:24 71

原创 124. 二叉树中的最大路径和

思路:递归计算左右子节点的最大贡献值。class Solution { int maxSum = Integer.MIN_VALUE; public int maxPathSum(TreeNode root) { maxGain(root); return maxSum; } public int maxGain(TreeNode node) { if (node == null) { retu..

2021-07-08 10:12:34 43

原创 20. 有效的括号

class Solution { public boolean isValid(String s) { int n = s.length(); if(n % 2 == 1) return false; Map<Character, Character> map = new HashMap<>(){{ put(')','('); put(']','[');

2021-07-05 23:24:51 52

原创 226. 翻转二叉树/剑指 Offer 27. 二叉树的镜像

思路一:递归特判:如果root为空,返回空把root的左子树放到mirrorTree中镜像一下把root的右子树放到mirrorTree中镜像一下交换左右子树返回根节点rootclass Solution { public TreeNode invertTree(TreeNode root) { if (root == null) { return null; } TreeNode left = invertTr

2021-07-05 16:37:07 63

原创 排序算法总结

排序专题冒泡插入选择快排堆排序冒泡插入选择快排堆排序class Solution { public int[] sortArray(int[] nums) { if(nums.length == 1 || nums.length == 0) return nums; quickSort(nums, 0, nums.length - 1); return nums; } public void quickSort(int

2021-07-04 19:28:16 68

原创 121. 买卖股票的最佳时机

我们需要找出给定数组中两个数字之间的最大差值(即,最大利润)。此外,第二个数字(卖出价格)必须大于第一个数字(买入价格)。形式上,对于每组 i 和 j(其中 j >i)我们需要找出 max(prices[j]−prices[i])。暴力法:超时public class Solution { public int maxProfit(int prices[]) { int maxprofit = 0; for (int i = 0; i < pric.

2021-07-02 17:16:55 58

原创 88. 合并两个有序数组

class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int[] ans = new int[m + n]; int p1 = 0, p2 = 0, index = 0; while(p1 < m && p2 < n){ if(nums1[p1] <= nums2[p2]){ .

2021-06-29 20:12:51 47

原创 146. LRU 缓存机制(Java实现)

要注意的点:双向链表的头尾节点都是伪节点。class LRUCache { // 双向链表 class DLinkedNode{ int val; int key; DLinkedNode next, prev; public DLinkedNode(){} public DLinkedNode(int key, int val){ this.key = key; .

2021-06-29 16:35:32 104

原创 剑指 Offer 68 - II. 二叉树的最近公共祖先

思路:通过递归对二叉树进行后序遍历,当遇到节点 p 或 q 时返回。从底至顶回溯,当节点 p, q 在节点 root的异侧时,节点 root 即为最近公共祖先,则向上返回 root四种情况:class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null) return null; // 如果p和q中有等.

2021-06-29 09:48:09 50

原创 300. 最长递增子序列

注意:子序列是可以不连续的思路:动态规划,:定义 dp[i] 表示以 nums[i] 这个数结尾的最⻓递增⼦序列的长度。初始化:dp 数组应该全部初始化为 1,因为子序列最少也要包含自己,所以长度最小为 1。class Solution { public int lengthOfLIS(int[] nums) { int len = nums.length; if(len < 2) return len; int[] dp = new i.

2021-06-28 12:31:41 84

原创 63. 不同路径 II

class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { if(obstacleGrid == null || obstacleGrid[0].length == 0) return 0; int m = obstacleGrid.length, n = obstacleGrid[0].length; int[][] dp = new int[m][n];.

2021-06-27 21:53:37 96 1

原创 62. 不同路径

思路:dp[i][j] 表示从 位置[0,0] 到 [i,j] 路径的总数,注意第一行只能从左边走过来,第一列只能从上面走过来,所以应该特殊对待。class Solution { public int uniquePaths(int m, int n) { int[][] dp = new int[m][n]; dp[0][0] = 1; for(int i = 0; i < m; i++){ dp[i][0] = 1.

2021-06-27 21:29:47 42

原创 53. 最大子序和

思路1.暴力2.动态规划,dp[i] 表示以 nums[i] 结尾的最大子数组的和3.动态规划优化----滚动数组1.暴力class Solution { public int maxSubArray(int[] nums) { // 初始化最大值 int max = Integer.MIN_VALUE; for(int i = 0; i < nums.length; i++){ int sum = 0; .

2021-06-27 20:29:05 83

原创 常用设计模式

常用设计模式单例模式源码中的应用应用场景步骤:饿汉式懒汉式双重校验锁为什么要两个if?工厂模式(买车例子)定义与使用场合简单工厂模式源码中的使用工厂方法模式抽象工厂模式代理模式适配器模式装饰器模式源码中的使用单例模式  优点:实现了整个程序对唯一实例访问的控制。因为单例要求程序只能有一个对象,所以对于那些需要频繁创建和销毁的对象来说可以提高系统的性能,并且可以节省内存空间。  缺点:如果实例化的对象长时间不被利用,系统会认为该对象是垃圾而被回收,可能会导致对象状态的丢失源码中的应用  1. jav

2021-06-26 23:04:18 139 1

原创 215. 数组中的第K个最大元素

思路:堆排序,大根堆用于升序,小根堆用于降序。注意循环次数,应该是 k - 1 次,比如 k = 2,那么应该删除 1 次class Solution { public int findKthLargest(int[] nums, int k) { int heapSize = nums.length; buildMaxHeap(nums, heapSize); for(int i = nums.length - 1; i > nums.le.

2021-06-24 11:32:43 55

空空如也

空空如也

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

TA关注的人

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