自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 剑指offer

剑指offer—持续更新 剑指 Offer 03. 数组中重复的数字 剑指 Offer 04. 二维数组中的查找 剑指 Offer 05. 替换空格

2021-01-21 14:32:40 140

原创 spring中util:list使用不规范引发的问题

七月 30, 2021 10:45:33 下午 org.springframework.context.support.AbstractApplicationContext refresh 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bea

2021-07-31 09:10:13 385

原创 记录spring中给list类型通过构造方法赋值时的愚蠢操作

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 28 in XML document from class path resource [ioc.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 28; columnNumber: 32; cvc-complex-type.2.4.d: 发现了以元

2021-07-30 22:06:20 270

原创 idea+maven+spring

at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304) at org.springframe

2021-07-30 16:31:53 242

原创 debug 修炼场

Debug 养成中

2021-07-30 16:27:48 153

原创 只出现一次的数字

只出现一次的数字 class Solution { public int singleNumber(int[] nums) { int res = 0; for (int num : nums) { res ^= num; } return res; } }

2021-03-23 10:00:03 139

原创 最长连续序列

最长连续序列 class Solution { public int longestConsecutive(int[] nums) { int res = 0; HashSet<Integer> hashSet = new HashSet<>(); for (int num : nums) { hashSet.add(num); } for (int num : nums)

2021-03-22 11:03:46 157

原创 单词搜索

单词搜索 class Solution { public boolean exist(char[][] board, String word) { for (int i = 0; i < board.length; i++) { for (int i1 = 0; i1 < board[0].length; i1++) { if (dfs(i, i1, word, board, 0)) return .

2021-03-20 14:52:15 148

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

二叉树中的最大路径和 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode() {} * TreeNode(int val) { this.val = val; } * TreeNode(int val, TreeNode left, TreeNode

2021-03-20 14:48:06 116

原创 合并二叉树

合并二叉树 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {

2021-03-19 11:03:17 126

原创 二叉树的序列化与反序列化

二叉树的序列化与反序列化 import java.util.*; public class Codec { String sequence = ""; public String serialize(TreeNode root) { if (root == null) { sequence += "null,"; return sequence; } sequence += root.val +

2021-03-19 10:21:30 124

原创 把二叉搜索树转换为累加树

把二叉搜索树转换为累加树 /* 中序遍历反向操作,遍历右子树、根节点、左子树 */ class Solution { TreeNode pre = null; int sum = 0; public TreeNode convertBST(TreeNode root) { rInorder(root); return root; } public void rInorder(TreeNode root) { if (ro

2021-03-18 10:55:23 127

原创 翻转二叉树

翻转二叉树 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { public TreeNode invertTree(TreeNode root) { if

2021-03-18 10:29:06 129

原创 二叉树的最近公共祖先

二叉树的最近公共祖先 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ class Solution { TreeNode ans = null; public TreeNode lowestC.

2021-03-17 11:01:45 118

原创 单词搜索

单词搜索 class Solution { public boolean exist(char[][] board, String word) { for (int i = 0; i < board.length; i++) { for (int i1 = 0; i1 < board[0].length; i1++) { if (dfs(i, i1, word, board, 0)) return .

2021-03-15 11:33:03 175

原创 子集

子集 class Solution { List<List<Integer>> res = new LinkedList<>(); public List<List<Integer>> subsets(int[] nums) { dfs(nums, 0, new LinkedList<>()); return res; } public void dfs(int[] num

2021-03-14 15:54:57 162

原创 颜色分类

颜色分类 /* [0, j - 1]: 为0所在区间 [j, i - 1] :为1所在区间 [k + 1, n - 1]:为2所在区间 */ class Solution { public void sortColors(int[] nums) { for (int i = 0, j = 0, k = nums.length - 1; i <= k;) { if (nums[i] == 0) swap(nums, j ++, i ++);

2021-03-14 10:49:04 617

原创 编辑距离

编辑距离 class Solution { public int minDistance(String word1, String word2) { int len1 = word1.length(), len2 = word2.length(); word1 = " " + word1; word2 = " " + word2; int[][] f = new int[len1 + 1][len2 + 1]; for.

2021-03-14 10:20:18 128

原创 爬楼梯

爬楼梯 class Solution { public int climbStairs(int n) { if (n == 1) return 1; int[] f = new int[n + 1]; f[1] = 1; f[2] = 2; for (int i = 3; i <= n; i ++) { f[i] = f[i - 1] + f[i - 2]; }

2021-03-11 11:35:24 132

原创 最小路径和

最小路径和 class Solution { public int minPathSum(int[][] grid) { int[][] f = new int[grid.length][grid[0].length]; for (int i = 0; i < grid.length; i ++) { for (int j = 0; j < grid[0].length; j ++) { if (i

2021-03-11 11:30:31 119

原创 不同路径

不同路径 /* 动态规划版本 */ class Solution { public int uniquePaths(int m, int n) { int[][] f = new int[m][n]; for (int i = 0; i < m; i ++) { for (int j = 0; j < n; j ++) { if (i == 0) f[i][j] = 1;

2021-03-09 16:53:53 139

原创 合并区间

合并区间 class Solution { public int[][] merge(int[][] intervals) { if (intervals.length == 1) return intervals; Arrays.sort(intervals, (o1, o2) -> o1[0] - o2[0]); LinkedList<LinkedList<Integer>> out = new LinkedList&

2021-03-09 16:06:22 134

原创 跳跃游戏

跳跃游戏 /* j : 能够跳到最远位置 i : 当前是否能够跳到的位置 */ class Solution { public boolean canJump(int[] nums) { for (int i = 0, j = 0; i < nums.length; i ++) { if (j < i) return false; j = Math.max(j, nums[i] + i); }

2021-03-08 12:05:25 110

原创 旋转图像

旋转图像 class Solution { public void rotate(int[][] matrix) { for (int i = 0; i < matrix.length; i ++) { for (int i1 = 0; i1 < matrix[0].length; i1 ++) { if (i < i1) { int tmp = matrix[i][i1

2021-03-08 11:46:53 106

原创 字母异位词分组

字母异位词分组 /* hashMap.computeIfAbsent(s, key -> new LinkedList<>()); hashmap中是否存在键s,不存在则创建键s,并添加值。 */ class Solution { public List<List<String>> groupAnagrams(String[] strs) { List<List<String>> res = new LinkedLi

2021-03-07 16:29:31 117

原创 组合总和

组合总和 class Solution { List<List<Integer>> res = new LinkedList<>(); public List<List<Integer>> combinationSum(int[] candidates, int target) { dfs(0, candidates, new LinkedList<>(), target); return

2021-03-06 11:00:41 144

原创 全排列

全排列 /* u : 搜索第u个位置 */ class Solution { List<List<Integer>> res = new LinkedList<>(); public List<List<Integer>> permute(int[] nums) { dfs(0, nums, new LinkedList<>(), new boolean[nums.length]); r

2021-03-06 10:59:05 114

原创 在排序数组中查找元素的第一个和最后一个位置

在排序数组中查找元素的第一个和最后一个位置 class Solution { public int[] searchRange(int[] nums, int target) { if (nums.length == 0) return new int[] {-1, -1}; int left = -1, right = -1; int l = 0, r = nums.length - 1; while (l < r) {

2021-03-05 16:53:57 120

原创 搜索旋转排序数组

搜索旋转排序数组 class Solution { public static int search(int[] nums, int target) { int l = 0, r = nums.length - 1; while (l < r) { int mid = l + r + 1 >> 1; if (nums[mid] >= nums[0]) { l = m

2021-03-05 15:45:44 140

原创 下一个排列

下一个排列 /* 4 5 3 2 1 从后向前找第一个非降序元素. 从非降序后找大于非降序元素的最小值,两个交换,将非降序元素后的元素排序 */ class Solution { public void nextPermutation(int[] nums) { int k = nums.length - 1; while (k > 0 && nums[k - 1] >= nums[k]) k --;

2021-03-04 11:42:38 192 1

原创 最长有效括号

最长有效括号 /* f[i] = ')' f[i - 1] = '(' f[i] = f[i - 2] + 2; f[i] = ')' f[i - 1] = ')' if (s[i - f[i - 1] - 1] == '(') f[i] = f[i - 1] + 2 + f[i - f[i - 1] - 2]; */ class Solution { public int longestValidParentheses(String s) {

2021-03-04 11:13:38 212 1

原创 正则表达式匹配

正则表达式匹配 class Solution { public boolean isMatch(String s, String p){ int n = s.length(), m = p.length(); boolean[][] f = new boolean[n + 1][m + 1]; s = " " + s; p = " " + p; f[0][0] = true; for (int i = 0

2021-02-27 21:18:45 142

原创 寻找两个正序数组的中位数

寻找两个正序数组的中位数 class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { int n = nums1.length + nums2.length; if (n % 2 == 0) { int k = n / 2; int x = findKth(nums1, 0, nums2, 0, k + 1);

2021-02-27 19:19:20 137

原创 买卖股票的最佳时机

买卖股票的最佳时机 /* 记录第i个元素之前的最小值,第i元素与最小值的差值的最大值便求得最大利润 */ class Solution { public int maxProfit(int[] prices) { int min = Integer.MAX_VALUE; int res = 0; for (int i = 0; i < prices.length; i++) { res = Math.max(res, p

2021-02-20 11:46:39 122

原创 乘积最大子数组

乘积最大子数组 /* f[i] = max(num[i], num[i] * num[i - 1], num[i] * num[i - 1] * num[i - 2],...) = max(num[i], num[i] * f[i - 1]); 从这里看与“53. 最大子序和”非常类似。但是乘法存在负负为正。因此,当num[i] < 0, f[i] = max(num[i], num[i] * f[i - 1]);其中需要f[i - 1] 位置应该是最小的。因此,定义g[i] 作为最小值。 此时:

2021-02-19 16:17:50 179

原创 最大子序和

最大子序和 /* f[i]: 以第i个元素结尾的连续子数组的和 f[i] = max(num[i], num[i] + num[i - 1]....) = num[i] + max(0, num[i - 1], num[i - 1] + nums[i -2]...) f[i - 1] = max(num[i - 1], num[i - 1] + num[i - 2]....) 所以动态转移方程:f[i] = nums[i] + max(0, f[i - 1]); */ class Solution {

2021-02-19 14:30:53 123

原创 最长递增子序列

最长递增子序列 /* f[i] 第i个元素结尾的递增子序列长度 */ class Solution { public int lengthOfLIS(int[] nums) { int n = nums.length; int[] f = new int[n + 1]; for (int i = 1; i <= n; i ++) { f[i] = 1; for (int j = 1; j <

2021-02-19 12:38:56 121

原创 最小栈

最小栈 /* 1. 使用一个单独栈保存最小值 2. 对于当前元素等于最小值栈顶元素也需要进栈 3. getMin() 当最小值栈为空,栈最小值为0. */ class MinStack { Stack<Integer> stack = new Stack<>(); Stack<Integer> stack1 = new Stack<>(); public void push(int x) { stack.add(x);

2021-02-17 20:53:03 121

原创 相交链表

相交链表 public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode p = headA, q = headB; while (p != q) { p = p == null ? headB : p.next; q = q == null ? headA : q.next;

2021-02-17 20:35:15 103

原创 多数元素

多数元素 注解: /* r: 表示当前存的数 c: 表示当前存储数的个数 遍历数组,当元素与r相等,c ++; 否则,消耗掉当前数的个数即c --; 由于某个数出现的次数大于剩余所有数出现次数的和,因此最终的r一定是要求的结果. 因为次数大于n/2不可能被消耗完. */ class Solution { public int majorityElement(int[] nums) { int r = 0, c = 0; for (int num : nums) {

2021-02-16 23:10:56 148

空空如也

空空如也

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

TA关注的人

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