repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution62.java
data_struct_study/src/dynamic_problem/Solution62.java
package dynamic_problem; import java.util.Arrays; /** * 不同路径:要么【用数学递推公式】, * * 要么就根据定义【直接计算】。直接计算时需要注意 * * Java “/”的整除性质,溢出,乘除顺序。 */ public class Solution62 { public int uniquePaths(int m, int n) { int[] dp = new int[n]; Arrays.fill(dp, 1); for (int i = 1; i < m; i++) { f...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution64.java
data_struct_study/src/dynamic_problem/Solution64.java
package dynamic_problem; /** * 最小路径和:其实到达某点的最小路径,只与该点数值、到达该点左边 * 的最小路径、到达该点上边的最小路径有关。所以只要找到 * 【正确循环顺序】,就可以避免所有的中间储存,两层循环即可。 */ public class Solution64 { public int minPathSum(int[][] grid) { if (grid == null || grid.length == 0 || grid[0].length == 0) { return 0; } int m ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution1143.java
data_struct_study/src/dynamic_problem/Solution1143.java
package dynamic_problem; import java.util.Arrays; /** * 题目描述:给定两个字符串 text1 和 text2,返回这两个字符串的最长公共子序列的长度。 * 一个字符串的 子序列 是指这样一个新的字符串:它是由原字符串在不改变字符的相对顺序的 * 情况下删除某些字符(也可以不删除任何字符)后组成的新字符串。 * 例如,"ace" 是 "abcde" 的子序列,但 "aec" 不是 "abcde" 的子序列。 * 两个字符串的「公共子序列」是这两个字符串所共同拥有的子序列。 * 若这两个字符串没有公共子序列,则返回 0。 * * 1、记忆化数组 + 递归(自上...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution416_2.java
data_struct_study/src/dynamic_problem/Solution416_2.java
package dynamic_problem; /** * O(n * sum) * O(n * sum) */ public class Solution416_2 { public boolean canPartition(int[] nums) { // 1、判断 nums 数组的和是否为偶数 int n = nums.length; int sum = 0; for (int i = 0; i < n; i++) { if (nums[i] <= 0) { throw new Ille...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution221.java
data_struct_study/src/dynamic_problem/Solution221.java
package dynamic_problem; /** * 最大正方形:可以用动态规划,以某点为右下角的最大正方形边长 只与 * 以该点上面、左边、左上相邻点为右下角的最大正方形边长有关, * 取最小+1的关系。用二维数组储存结果需要补充上边和左边的 * 数组 2d dp,也可以用一位数组储存结果,更节约空间 1d dp。 */ public class Solution221 { public int maximalSquare(char[][] matrix) { int row = matrix.length; int col = matrix.length==0? 0:...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution1143_2.java
data_struct_study/src/dynamic_problem/Solution1143_2.java
package dynamic_problem; /** * 2、记忆化数组 + DP(自下而上):躲避边界条件 * 时间复杂度:O((len(s1) * len(s2)) * 空间复杂度:O((len(s1) * len(s2)) */ public class Solution1143_2 { // 2、记忆化数组 + DP(自下而上):躲避边界条件 public int longestCommonSubsequence(String s1, String s2) { // 1、如果s1或s2等于null,则抛出异常 if (s1 == null || s2 == n...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution70.java
data_struct_study/src/dynamic_problem/Solution70.java
package dynamic_problem; import java.util.Arrays; /** * 1、记忆化搜索 + 递归(自上而下) * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution70 { private int[] memo; // 1、记忆化搜索 + 递归(自上而下) // 时间复杂度:O(n),空间复杂度:O(n) public int climbStairs(int n) { // 1、创建记忆数组避免重复运算 memo = new int[n + 1]; A...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution279.java
data_struct_study/src/dynamic_problem/Solution279.java
package dynamic_problem; import java.util.ArrayList; import java.util.List; public class Solution279 { public int numSquare(int n) { List<Integer> squareList = generateSquareList(n); int[] dp = new int[n + 1]; for (int i = 1; i <= n; i++) { int min = Integer.MAX_VALUE; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution53.java
data_struct_study/src/dynamic_problem/Solution53.java
package dynamic_problem; /* LeetCode Problem No.53: https://leetcode.com/problems/maximum-subarray/ Idea: maxEndingHere, maxSoFar -> compare from the end of subarray instead of beginning Time: 1 ms, beat 99.96% Space: 39.5MB, beat 71.04% */ class So...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution198_5.java
data_struct_study/src/dynamic_problem/Solution198_5.java
package dynamic_problem; import java.util.Arrays; /** * 记忆化搜索:优化状态转移 * O(n) * O(n) */ public class Solution198_5 { private int[] memo; public int rob(int[] nums) { memo = new int[nums.length]; Arrays.fill(memo, -1); return tryRob(nums, 0); } private int tryRob(int[] nums...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution198_7.java
data_struct_study/src/dynamic_problem/Solution198_7.java
package dynamic_problem; import java.util.Arrays; /** * 记忆化搜索:改变状态定义,优化转移方程 * O(n) * O(n) */ public class Solution198_7 { private int[] memo; public int rob(int[] nums) { memo = new int[nums.length]; Arrays.fill(memo, -1); return tryRob(nums, nums.length - 1); } private ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution509_2.java
data_struct_study/src/dynamic_problem/Solution509_2.java
package dynamic_problem; import java.util.Arrays; /** * 记忆化搜索 + 递归 */ public class Solution509_2 { private int[] memo; public int fib(int n) { memo = new int[n + 1]; Arrays.fill(memo, -1); return fib(n, memo); } private int fib(int n, int[] memo) { if (n == 0) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution.java
data_struct_study/src/dynamic_problem/Solution.java
package dynamic_problem; /** * 背包问题 * 记忆化搜索 => DP => DP + 滚动数组 => DP + 优化状态转移方程 * O(n * C) * O(C) */ public class Solution { public int knapsack(int[] w, int[] v, int C){ if (w == null || v == null || w.length != v.length) { throw new IllegalArgumentException("illegal argument!"); ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution121.java
data_struct_study/src/dynamic_problem/Solution121.java
package dynamic_problem; /** * 题目描述: * 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 * 如果你最多只允许完成一笔交易(即买入和卖出一支股票一次), * 设计一个算法来计算你所能获取的最大利润。 * * 1、穷举框架-状态与选择: * for 状态1 in 状态1的所有取值: * for 状态2 in 状态2的所有取值: * for ... * dp[状态1][状态2][...] = 择优(选择1,选择2...) * 这里每天都有三种「选择」:买入、卖出、无操作。 * 「状态」有三个,第一个是天数...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution70_2.java
data_struct_study/src/dynamic_problem/Solution70_2.java
package dynamic_problem; import java.util.Arrays; /** * 2、记忆化搜索 + DP(自下而上) * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution70_2 { // 2、记忆化搜索 + DP(自下而上) // 时间复杂度:O(n), 空间复杂度:O(n) public int climbStairs(int n) { // 1、创建记忆数组并全部填充为-1 int[] memo = new int[n + 1]; Arrays.fill(mem...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution322.java
data_struct_study/src/dynamic_problem/Solution322.java
package dynamic_problem; import java.util.Arrays; public class Solution322 { public int coinChange(int[] coins, int amount) { int max = amount + 1; int[] dp = new int[amount + 1]; Arrays.fill(dp, max); dp[0] = 0; for (int i = 1; i <= amount; i++) { for (int j =...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution494_2.java
data_struct_study/src/dynamic_problem/Solution494_2.java
package dynamic_problem; public class Solution494_2 { public int findTargetSumWays(int[] nums, int S) { return findTargetSumWays(nums, 0, S); } private int findTargetSumWays(int[] nums, int start, int s) { if (start == nums.length) { return s == 0 ? 1 : 0; } r...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution343.java
data_struct_study/src/dynamic_problem/Solution343.java
package dynamic_problem; /** * 发现重叠的子问题 * 1、暴力解法:回溯遍历将一个树做分割的所有可能性。 * 2、记忆化搜索 * 2、动态规划。 * O(n ^ n) * O(n) */ public class Solution343 { public int integerBreak(int n) { if (n < 1) { throw new IllegalArgumentException("n is illegal argument"); } return b...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution239.java
data_struct_study/src/dynamic_problem/Solution239.java
package dynamic_problem; import java.util.ArrayList; import java.util.PriorityQueue; public class Solution239 { public ArrayList<Integer> maxInWindows(int[] num, int size) { ArrayList<Integer> ret = new ArrayList<>(); if (size > num.length || size < 1) return ret; PriorityQueu...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution309.java
data_struct_study/src/dynamic_problem/Solution309.java
package dynamic_problem; /** * 最佳买卖股票时机含冷冻期: 重点在于【状态划分】,我们要确保这样 * 的状态划分保证每一笔交易都有冷冻期。 * * sold:在当天卖出股票,必须由hold状态而来。 hold:当天持有股票, * 可能是当天买入,或者之前买入的。可以由rest或者hold状态而来。 * rest:当天不持有股票,可能是前一天卖出的,也可能是更早卖出的。 * 可以由sold或者rest状态而来。 这样的状态划分,我们可以看到, * 要从sold状态进入hold状态必须经过至少一次的rest,这就满足了 * 冷冻期的要求。需要注意的是初始值的选取,可以通过对第一天情况 ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution474.java
data_struct_study/src/dynamic_problem/Solution474.java
package dynamic_problem; public class Solution474 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution198_2.java
data_struct_study/src/dynamic_problem/Solution198_2.java
package dynamic_problem; /** * DP * O(n^2) * O(n) */ public class Solution198_2 { public int rob(int[] nums) { int len = nums.length; if (len == 0) { return 0; } int[] memo = new int[len]; memo[len - 1] = nums[len - 1]; for (int i = len - 2; i >= 0...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution300.java
data_struct_study/src/dynamic_problem/Solution300.java
package dynamic_problem; import java.util.Arrays; /** * 题目描述:给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。 * 子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。 * 例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。 * * 最长上升子序列: * 1、暴力解法:选择所有的子序列进行判断。O((2^n)*n) * 2、LIS(i) 表示[0...i]的范围内,选择数字nums[i]可以获得的最长上升子序列的长度。 * LIS(i) = max(1...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution376.java
data_struct_study/src/dynamic_problem/Solution376.java
package dynamic_problem; /** * 最长公共子序列 LCS * 1、LCS(m, n) S1[0...m] 和 S2[0...n] 的最长公共子序列的长度。 * S1[m] == S2[n]: LCS(m, n) = 1 + LCS(m-1, n-1) * S1[m] != S2[n]: LCS(m, n) = max( LCS(m-1, n), LCS(m, n-1)) * * dijkstra 单源最短路径算法也是动态规划 * 1、shortestPath(i) 为从start到i的最短路径长度。 * shortestPath(x) ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution343_3.java
data_struct_study/src/dynamic_problem/Solution343_3.java
package dynamic_problem; import java.util.Arrays; /** * dp + 记忆化搜索 * O(n ^ 2) * O(n) */ public class Solution343_3 { private int[] memo; public int integerBreak(int n) { if (n < 1) { throw new IllegalArgumentException("n is illegal argument!"); } memo = new int[n + ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Main.java
data_struct_study/src/dynamic_problem/Main.java
package dynamic_problem; /** * 什么是动态规划? * 斐波那契数列——解决递归中的 重叠子问题 && 最优子结构:通过求子问题的最优解,可以获得原问题的最优解: * 1、记忆化搜索避免重复运算,自上而下的解决问题。 * 2、动态规划,自下而上的解决问题。 * 动态规划将是将原问题拆解成若干个子问题,同时保存子问题的答案, * 使得每个子问题只求解一次,最终获得原问题的答案。 * * JsonChao的动态规划核心题库:26题 */ public class Main { public static void...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution337.java
data_struct_study/src/dynamic_problem/Solution337.java
package dynamic_problem; public class Solution337 { public static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public int rob(TreeNode root) { if (root == null) { return 0; } // 1、计算第 1、3...层节点...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution72.java
data_struct_study/src/dynamic_problem/Solution72.java
package dynamic_problem; /** * 动态规划给出具体解 * 反向求出具体的解,甚至是所有的解。 * 编辑距离 72 */ public class Solution72 { public int minDistance(String word1, String word2) { // 1、创建 dp 数组并赋值上边界和左边界 if (word1 == null || word2 == null) { return 0; } int m = word1.length(); ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution122.java
data_struct_study/src/dynamic_problem/Solution122.java
package dynamic_problem; /** * 题目描述:给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 * 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。 * * 如果 k 为正无穷,那么就可以认为 k 和 k - 1 是一样的: * dp[i][k][0] = max(dp[i-1][k][0], dp[i-1][k][1] + prices[i]) * dp[i][k][1] = max(dp[i-1][k][1], dp[i-1][k-1][0] - prices[i]) * = max(dp[i-1][k]...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution494.java
data_struct_study/src/dynamic_problem/Solution494.java
package dynamic_problem; /** * 目标和:一个朴素的想法是用【暴力破解】 ,枚举所有的正负组合方式, * 对每一次结果进行筛选,但是这样就超时了。这样的暴力破解法也可以 * 写成【递归】 的形式(会导致一部分不可避免的重复运算)。 * 但其实呢,我们可以把所有的数分为两部分,第一部分用加号, * 第二部分用减号,由此可以得出用加号部分的和。问题就被转 * 化成了 416. 分割等和子集 ,即寻找子集使得和为某一特定 * 数字,每一个数字仅能用1次。 */ public class Solution494 { public int findTargetSumWays(int[] ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution416.java
data_struct_study/src/dynamic_problem/Solution416.java
package dynamic_problem; import java.util.Arrays; /** * 0-1背包问题 * 1、暴力解法:每一件物品都可以放进背包,也可以不放进背包。O((2^n)*n) * 2、动态规范——状态转移方程:F(n, C) 考虑将n个物品放进容量为C的背包,使得价值最大。 * F(n, C) = max(F(i-1, c), v(i) + F(i-1, c - w(i)) * O(n*C) O(n*C) * 3、优化:根据状态转移方程,第i行元素只依赖于第i-1行元素。理论上,只需要保持两行元素。 * 空间复杂度:O...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/dynamic_problem/Solution91.java
data_struct_study/src/dynamic_problem/Solution91.java
package dynamic_problem; public class Solution91 { public int numDecodings(String s) { if (s == null || s.length() == 0) { return 0; } // 1、预先处理 dp[0] 与 dp[1] int n = s.length(); int[] dp = new int[n + 1]; dp[0] = 1; dp[1] = s.charAt(0) == '0' ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/avl/FileOperation.java
data_struct_study/src/avl/FileOperation.java
package avl; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Locale; import java.util.Scanner; // 文件相关操作 public class FileOperation { // 读取文件名称为filename中的内容,并将其中包含的所有词语放进words中 public static bool...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/avl/AVLTree.java
data_struct_study/src/avl/AVLTree.java
package avl; import java.util.ArrayList; /** * AVL 的自平衡机制: * 1、左旋转 * 2、右旋转 * * 在什么时候维护平衡? * 加入节点后,沿着节点向上维护平衡性。 * * 时间复杂度 O(logn) * * AVL 优化:在维护每一个节点之前,都需要对 AVL 的高度进行重新的计算, * 但是如果我们重新计算出的这个节点的高度与原先的高度相等的话,对于这个 * 节点的祖先节点就不再需要维护平衡的操作了。这是因为这个节点的高度和原先 * 一样,从它的父亲节点和祖先节点来看,它的子树的高度并没有发送变化, * 所以不...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/avl/BST.java
data_struct_study/src/avl/BST.java
package avl; import java.util.ArrayList; public class BST<K extends Comparable<K>, V> { private class Node{ public K key; public V value; public Node left, right; public Node(K key, V value){ this.key = key; this.value = value; left = null; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/avl/Main.java
data_struct_study/src/avl/Main.java
package avl; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { System.out.println("Pride and Prejudice"); ArrayList<String> words = new ArrayList<>(); if(FileOperation.readFile("pride-and-prejudice.txt", words)) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution220.java
data_struct_study/src/hash_table_problem/Solution220.java
package hash_table_problem; import java.util.TreeSet; /** * 220: * 1、滑动窗口 + set.lower_bound,注意使用 long 运算,避免整形溢出。 * * O(nlog(k) * O(k) */ public class Solution220 { public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) { // 1、异常处理 if (nums == null || nums.length <= 1) ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution202.java
data_struct_study/src/hash_table_problem/Solution202.java
package hash_table_problem; /** * 202:陷入循环就不是 happy number。 */ public class Solution202 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution242.java
data_struct_study/src/hash_table_problem/Solution242.java
package hash_table_problem; /** * 242: * 1、空集 * 2、字符集 * * 可以用 HashMap 来映射字符与出现次数,然后比较两个字符串出现的字符数量是否相同。 * * 由于本题的字符串只包含 26 个小写字符,因此可以使用长度为 26 的整型数组 * 对字符串出现的字符进行统计,不再使用 HashMap。 */ public class Solution242 { public boolean isAnagram(String s, String t) { int[] countForNum = new int[26];...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution217.java
data_struct_study/src/hash_table_problem/Solution217.java
package hash_table_problem; import java.util.HashSet; import java.util.Set; /** * 219、217(简化版219): * 1、暴力枚举法:O(n^2) * 2、滑动窗口 + 查找表:O(n) 空间 O(k) */ public class Solution217 { public boolean containsDuplicate(int[] nums) { Set<Integer> hashSet = new HashSet<>(); for (int num:nums) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution18.java
data_struct_study/src/hash_table_problem/Solution18.java
package hash_table_problem; public class Solution18 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution1.java
data_struct_study/src/hash_table_problem/Solution1.java
package hash_table_problem; import java.util.HashMap; /** * Two Sum 系列——1: * 1、索引从0开始计算还是从1开始计算? * 2、没有解怎么办? * 3、有多个解怎么办?保证有唯一解。 * 4、暴力解法 O(n^2) * 5、排序后,使用双索引对撞:O(nlogn) + O(n) = O(nlogn) * 6、查找表(map),将所有元素放入查找表,之后对每一个元素 a,查找 target - a 是否存在。O(n) */ public class Solution1 { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution349.java
data_struct_study/src/hash_table_problem/Solution349.java
package hash_table_problem; import java.util.TreeSet; /** * 349(set)、350(map): * 1、C++ 中 map find 不到元素时输出 0 * * set 和 map 不同底层实现的区别 * 普通数组实现 顺序数组实现 二分搜索树(平衡) 哈希表 * 插入 O(1) O(n) O(logn) O(1) * 查找 O(n) O(logn) O(logn) ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution454.java
data_struct_study/src/hash_table_problem/Solution454.java
package hash_table_problem; import java.util.HashMap; /** * 454: * 1、暴力解法:O(n^4) * 2、将 D 中的元素放入查找表:O(n^3) * 3、将 C + D 的每一种可能放入查找表中:O(n^2) * * O(n^2) * O(n^2) */ public class Solution454 { public int fourSumCount(int[] A, int[] B, int[] C, int[] D) { if (A == null || B == null || ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution350_2.java
data_struct_study/src/hash_table_problem/Solution350_2.java
package hash_table_problem; import java.util.ArrayList; import java.util.HashMap; /** * O(len(nums1) + len(nums2)) * O(len(nums1)) */ public class Solution350_2 { public int[] intersect(int[] nums1, int[] nums2) { HashMap<Integer, Integer> record = new HashMap<>(); for (Integer item:nums1) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution209.java
data_struct_study/src/hash_table_problem/Solution209.java
package hash_table_problem; /** * 209: * 1、字符集? * 2、空串符合任意模式?还是不符合任意模式? */ public class Solution209 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution15.java
data_struct_study/src/hash_table_problem/Solution15.java
package hash_table_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * 题目描述:给你一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c , * 使得 a + b + c = 0 ?请你找出所有满足条件且不重复的三元组。 * * 注意:答案中不可以包含重复的三元组。 * 1、不同的三元组? * 2、如果有多个解,解的顺序? * 3、如果没有解。 * * 三数之和:需要尤其注意去重,有些繁琐。 */ ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution219.java
data_struct_study/src/hash_table_problem/Solution219.java
package hash_table_problem; import java.util.HashMap; import java.util.HashSet; /** * 219、217(简化版219): * 1、暴力枚举法:O(n^2) * 2、滑动窗口 + 查找表:O(n) 空间 O(k) * * O(n) * O(k) */ public class Solution219 { public boolean containsNearbyDuplicate(int[] nums, int k) { if (nums == null || nums.length ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution49.java
data_struct_study/src/hash_table_problem/Solution49.java
package hash_table_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; /** * 49: * 1、字符集 * 2、大小写敏感 */ public class Solution49 { public List<List<String>> groupAnagrams(String[] strs) { HashMap<String, List<String>> map=new HashMap<...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution205.java
data_struct_study/src/hash_table_problem/Solution205.java
package hash_table_problem; /** * 205: * 1、字符集 * 2、空串 * 3、一个字符是否可以映射到自己 * * 记录一个字符上次出现的位置,如果两个字符串中的字符上次出现的位置一样,那么就属于同构。 */ public class Solution205 { public boolean isIsomorphic(String s, String t) { int[] preIndexOfS = new int[256]; int[] preIndexOfT = new int[256]; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Main.java
data_struct_study/src/hash_table_problem/Main.java
package hash_table_problem; /** * 两类查找问题: * 1、查找有无:元素 a 是否存在?set;集合。 * 2、查找对应关系(键值对应):元素 a 出现了几次?map;字典。 * 常见操作: * 1、insert * 2、find * 3、erase * 4、change(map) * * JsonChao的哈希表核心题库:18题 */ public class Main { public static void main(String[] args) { } }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution_349_2.java
data_struct_study/src/hash_table_problem/Solution_349_2.java
package hash_table_problem; import java.util.HashSet; /** * O(len(nums1) + len(nums2)) * O(len(nums1)) */ public class Solution_349_2 { public int[] intersection(int[] nums1, int[] nums2) { HashSet<Integer> record = new HashSet<>(); for (Integer item:nums1) { record.add(item); ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution451.java
data_struct_study/src/hash_table_problem/Solution451.java
package hash_table_problem; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class Solution451 { public String frequencySort(String s) { // 1、创建 HashMap 字符:频率 HashMap<Character, Integer> freqCharMap = new HashMap<>(); for (Character c:s.toCharArray()) {...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution16.java
data_struct_study/src/hash_table_problem/Solution16.java
package hash_table_problem; /** * 18、16: * 1、如果有多个解,其和 target 值的接近程度一样怎么办? * 2、如果没解?(可不可能没解?) */ public class Solution16 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution1_2.java
data_struct_study/src/hash_table_problem/Solution1_2.java
package hash_table_problem; import java.util.Arrays; import java.util.HashMap; /** * O(n) * O(n) */ public class Solution1_2 { // 数组无序时:查找表(map),将所有元素放入查找表,之后对每一个元素 a, // 查找 target - a 是否存在, 时间复杂度O(n) public int[] twoSum(int[] arr, int target) { // 1、边界异常处理 int n = arr.length; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution350.java
data_struct_study/src/hash_table_problem/Solution350.java
package hash_table_problem; import java.util.ArrayList; import java.util.TreeMap; /** * 349(set)、350(map): * 1、C++ 中 map find 不到元素时输出 0 * * O(nlogn) * O(n) */ public class Solution350 { public int[] intersect(int[] nums1, int[] nums2) { TreeMap<Integer, Integer> record = new TreeMap<>(); ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution149.java
data_struct_study/src/hash_table_problem/Solution149.java
package hash_table_problem; /** * 149: * 1、点坐标的范围 * 2、点坐标的表示(整数?浮点数?浮点误差?) */ public class Solution149 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution447.java
data_struct_study/src/hash_table_problem/Solution447.java
package hash_table_problem; import java.util.HashMap; /** * 447: * 1、枚举法(暴力法):O(n^3) * 2、查找表,求距离的平方,避免浮点型运算(注意避免整形移除,当然,这个题不需要处理):O(n^2),空间 O(n) * * O(n^2) * O(n) */ public class Solution447 { public int numberOfBoomerangs(int[][] points) { int res = 0; for (int i = 0; i < poin...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table_problem/Solution454_2.java
data_struct_study/src/hash_table_problem/Solution454_2.java
package hash_table_problem; import java.util.HashMap; /** * O(n^2) * O(n^2) */ public class Solution454_2 { public int fourSumCount(int[] A, int[] B, int[] C, int[] D) { if (A == null || B == null || C == null || D == null) { throw new IllegalArgumentException("illegal argument!"); ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/NumArray2.java
data_struct_study/src/segment_tree/NumArray2.java
package segment_tree; class NumArray2 { private int[] sum; public NumArray2(int[] nums) { // sum[i + 1] 为 sum[0] - sum[i] 的和 // sum[0] = 0 sum = new int[nums.length + 1]; sum[0] = 0; for (int i = 1; i < sum.length; i++) { sum[i] = sum[i - 1] + nums[i - 1];...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/NumArray3.java
data_struct_study/src/segment_tree/NumArray3.java
package segment_tree; class NumArray3 { private final int[] data; private final int[] sum; public NumArray3(int[] nums) { data = new int[nums.length]; for (int i = 0; i < nums.length; i++) { data[i] = nums[i]; } sum = new int[nums.length + 1]; sum[0] ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/Merger.java
data_struct_study/src/segment_tree/Merger.java
package segment_tree; public interface Merger<E> { E merge(E a, E b); }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/SegmentTree.java
data_struct_study/src/segment_tree/SegmentTree.java
package segment_tree; /** * 为什么要使用 线段树? * 1、区间染色:m 次操作后,我们可以在区间 [i,j] 内看见多少种颜色? * 使用数组实现 线段树 * 染色操作(更新操作) O(n) O(logn) * 查询操作(查询区间) O(n) O(logn) * * 2、区间查询:查询一个区间的 最大值、最小值、后者区间数字和。 * 更新:更新区间中一个元素或者一个区间的值。 * 实质:基于区间的统计查询。 * * segment_tree.png * ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/Main.java
data_struct_study/src/segment_tree/Main.java
package segment_tree; public class Main { public static void main(String[] args) { Integer[] nums = {-2, 0, 3, -5, 2, -1}; SegmentTree<Integer> tree = new SegmentTree<>(nums, Integer::sum); System.out.println(tree); System.out.println(tree.query(0, 2)); System.out.println...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/segment_tree/NumArray.java
data_struct_study/src/segment_tree/NumArray.java
package segment_tree; class NumArray { public interface Merger<E> { E merge(E a, E b); } public class SegmentTree<E> { private Merger<E> merger; private E[] data; private E[] tree; public SegmentTree(E[] arr, Merger<E> merger) { this.merger = merger;...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Solution455_2.java
data_struct_study/src/greedy_problem/Solution455_2.java
package greedy_problem; import java.util.Arrays; /** * 先尝试满足最不贪心的小朋友 * O(nlogn) * O(1) */ public class Solution455_2 { public int findContentChildren(int[] g, int[] s) { // 1、排序 Arrays.sort(g); Arrays.sort(s); // 2、先尝试满足最不贪心的小朋友 int gi = 0; int si = 0; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Solution455.java
data_struct_study/src/greedy_problem/Solution455.java
package greedy_problem; import java.util.Arrays; /** * 先尝试将最大的饼干分配给最贪心的小朋友 * O(nlogn) * O(1) */ public class Solution455 { public int findContentChildren(int[] g, int[] s) { // 1、排序 Arrays.sort(g); Arrays.sort(s); // 2、先尝试将最大的饼干分配给最贪心的小朋友 int gi = g.length - 1; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Solution435_2.java
data_struct_study/src/greedy_problem/Solution435_2.java
package greedy_problem; import java.util.Arrays; import java.util.Comparator; /** * 设计贪心算法:按照区间的结尾排序,每次选择区间结尾最早的,且和前一个区间不重叠额的区间 * O(n) * O(n) */ public class Solution435_2 { // Definition for an interval. public static class Interval { int start; int end; Interval() { start = 0; e...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Solution435.java
data_struct_study/src/greedy_problem/Solution435.java
package greedy_problem; import java.util.Arrays; import java.util.Comparator; /** * 贪心算法与动态规划的关系 435: * 1、最多保留多少个区间。 * 2、暴力解法:找出所有子区间的组合,之后判断它不重叠。O((2^n)*n) * 3、排序后,动态规划——最常上升子序列模型。 * 4、注意:每次选择中,每个区间的结尾很重要,结尾越小,留给后面的空间越大,所以后面能容纳更多区间。 * ——设计出贪心算法:按照区间的结尾排序,每次选择结尾最早的,且和前一个区间不重叠的区间。 * ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Solution392.java
data_struct_study/src/greedy_problem/Solution392.java
package greedy_problem; public class Solution392 { public boolean isSubsequence(String s, String t) { int index = -1; for (char c:s.toCharArray()) { index = t.indexOf(c, index + 1); if (index == -1) { return false; } } return true...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/greedy_problem/Main.java
data_struct_study/src/greedy_problem/Main.java
package greedy_problem; /** * 贪心算法: 它也存在最小生成树与最短路径中。 * * JsonChao的贪心算法题库:3题 */ public class Main { public static void main(String[] args) { } }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack/ArrayStack.java
data_struct_study/src/stack/ArrayStack.java
package stack; import array.Array; /** * 栈的一种实现方式:使用动态数组实现栈 * * @param <E> 栈中的元素 */ public class ArrayStack<E> implements Stack<E> { private Array<E> array; public ArrayStack(int capacity) { array = new Array<>(capacity); } public ArrayStack() { array = new Array<>(); } ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack/Stack.java
data_struct_study/src/stack/Stack.java
package stack; /** * Stack 的抽象接口化 * @param <E> */ public interface Stack<E> { /** * 入栈 * * @param e 入栈的元素 */ void push(E e); /** * 出栈 * * @return e 出栈的元素 */ E pop(); /** * 查看栈顶的元素 * * @return e 栈顶的元素 */ E peek(); /** *...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack/Main.java
data_struct_study/src/stack/Main.java
package stack; /** * 栈的应用: * 1)、无处不在的撤销操作 * 2)、系统栈的调用(操作系统) * 3)、括号匹配(编译器) */ public class Main { public static void main(String[] args) { ArrayStack<Object> stack = new ArrayStack<>(); for (int i = 0; i < 5; i++) { stack.push(i); System.out.println(s...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack/Paththesees.java
data_struct_study/src/stack/Paththesees.java
package stack; class Paththesees { public boolean isValid(String s) { // 1、注意 stack 中存的是字符: Character Stack<Character> stack = new ArrayStack<>(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); // 2、在 Java 中字符以 '' 标记,如果当前字符是左括号则放入栈中 if (c ==...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table/Solution1.java
data_struct_study/src/hash_table/Solution1.java
package hash_table; /** * https://leetcode-cn.com/problems/first-unique-character-in-a-string/ */ class Solution1 { public int firstUniqChar(String s) { int[] hashTable = new int[26]; for (int i = 0; i < s.length(); i++) { hashTable[s.charAt(i) - 'a']++; } for (int ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table/HashTable.java
data_struct_study/src/hash_table/HashTable.java
package hash_table; import java.util.TreeMap; public class HashTable<K, V> { private final int[] capacity = {53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 2013266...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table/Student.java
data_struct_study/src/hash_table/Student.java
package hash_table; public class Student { int grade; int cls; String firstName; String lastName; Student(int grade, int cls, String firstName, String lastName){ this.grade = grade; this.cls = cls; this.firstName = firstName; this.lastName = lastName; } @O...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/hash_table/Main.java
data_struct_study/src/hash_table/Main.java
package hash_table; import avl.AVLTree; import avl.BST; import avl.FileOperation; import red_black_tree.RBTree; import java.util.ArrayList; /** * 什么是哈希函数? * * 哈希函数:将 "键" 转换为 "索引",每一个 "键" 对应唯一的一个索引。 * * 很难保证每一个 "键" 通过哈希函数的转换对应不同的 "索引",因此会产生哈希冲突。 * "键" 通过哈希函数得到的 "索引" 分布越均匀越好。 * * 在哈希表(空间换时间)上操作,主要要考虑如何解决哈希冲突。...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/queue/LoopQueue.java
data_struct_study/src/queue/LoopQueue.java
package queue; /** * 循环队列: * 采用队尾和队首两个指针:front、tail,目的是将普通队列中的 出队 * 时间复杂度降为 O(1),省去复制数组的操作。 * * * @param <E> */ public class LoopQueue<E> implements Queue<E> { private E[] data; private int front, tail; private int size; public LoopQueue(int capacity) { data = (E[]) new Obje...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/queue/ArrayQueue.java
data_struct_study/src/queue/ArrayQueue.java
package queue; /** * 数组队列实现: * 其中 enqueue 的时间复杂度为 O(n),需要使用循环队列改进为 O(1)。 * * @param <E> */ public class ArrayQueue<E> implements Queue<E> { private Array<E> array; public ArrayQueue() { array = new Array<>(); } public ArrayQueue(int capacity) { array = new Array<>(capacity...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/queue/Array.java
data_struct_study/src/queue/Array.java
package queue; /** * 1、实现基本功能:增删改查、各种判断方法等等 * 2、使用 泛型 让我们的数据结构可以放置 "任何"(不可以是基本 * 数据类型,只能是类对象,好在每一个基本类型都有一个对应的 * 包装类,它们之间可以自动进行装箱和拆箱的操作) 的数据类型 * 3、数组的扩容与缩容 * * 手写时的易错点: * 1、注意数组的下标 * 2、注意 size 与 capacity 的区别 * * 简单的时间复杂度分析: * 为什么要用大O,叫做大O(n)? * 忽略了常数,实际时间 T = c1 * n + c2 * ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/queue/Main.java
data_struct_study/src/queue/Main.java
package queue; import LinkedList.LinkedListQueue; import java.util.Random; public class Main { // 测试使用q运行opCount个enqueueu和dequeue操作所需要的时间,单位:秒 private static double testQueue(Queue<Integer> q, int opCount){ long startTime = System.nanoTime(); Random random = new Random(); for(int i...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/queue/Queue.java
data_struct_study/src/queue/Queue.java
package queue; public interface Queue<E> { void enqueue(E e); E dequeue(); boolean isEmpty(); int getSize(); E getFront(); }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution94.java
data_struct_study/src/stack_problem/Solution94.java
package stack_problem; import java.util.ArrayList; import java.util.List; /** * O(n):树中的节点个数。 * O(h):树的高度。 */ public class Solution94 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val =...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution_1.java
data_struct_study/src/stack_problem/Solution_1.java
package stack_problem; import java.util.Stack; /** * 用两个栈来实现一个队列,完成队列的 Push 和 Pop 操作。 * * 1、in 栈用来处理入栈操作,out 栈用来处理出栈操作。 * 一个元素进入 in 栈之后,出栈的顺序被反转。当元素要出栈时, * 需要先进入 out 栈,此时元素出栈顺序再一次被反转,因此出栈顺序 * 就和最开始入栈顺序是相同的,先进入的元素先退出,这就是队列的顺序。 * * 2、在in栈中写入,要输出时,将所有in栈数据移到out栈,然后只要out栈数据不为空, * 就可以一直取出,一旦为空,则再将in栈数据移到out栈中即可。 ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution341.java
data_struct_study/src/stack_problem/Solution341.java
package stack_problem; /** * 341:对于 [1[4,[6]]], 在 hasNext() 为 true 的情况下,不断调用 next(), 依次获得 1 4 6。 */ public class Solution341 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution94_2.java
data_struct_study/src/stack_problem/Solution94_2.java
package stack_problem; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * 模拟系统栈,非递归二叉树的中序遍历 * O(n) * O(h) */ public class Solution94_2 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; Tre...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution71.java
data_struct_study/src/stack_problem/Solution71.java
package stack_problem; /** * 71: * 1、这个路径是否一定合法? * 2、不能回退的情况?(如 /../, 返回 /) * 3、多余的 /?(如 /home//hello/, 返回 /home/hello) */ public class Solution71 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution144.java
data_struct_study/src/stack_problem/Solution144.java
package stack_problem; import java.util.ArrayList; import java.util.List; /** * 144、94、145: * 1、递归实现。 * 2、循环实现:使用栈模拟系统栈,写出非递归程序。 * O(n) * O(h) */ public class Solution144 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution20.java
data_struct_study/src/stack_problem/Solution20.java
package stack_problem; import java.util.Stack; /** * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution20 { public boolean isValid(String s) { // 1、创建一个栈,注意 stack 中存的是字符:Character Stack<Character> stack = new Stack<>(); // 2、遍历字符串 for (int i = 0; i < s.length(); i++) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution155.java
data_struct_study/src/stack_problem/Solution155.java
package stack_problem; import java.util.Stack; /** * 使用双栈(数据栈+最小值栈)+min实现最小值栈 */ public class Solution155 { private Stack<Integer> mDataStack; private Stack<Integer> mMinStack; private int min; public Solution155() { // 1、创建一个数据栈保存数据,最小值栈的栈顶维护最小值,min变量维护最小值 mDataStack = new Stack<...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution145.java
data_struct_study/src/stack_problem/Solution145.java
package stack_problem; import java.util.ArrayList; import java.util.List; /** * O(n) * O(h) */ public class Solution145 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public Li...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution145_2.java
data_struct_study/src/stack_problem/Solution145_2.java
package stack_problem; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * O(n) * O(h) */ public class Solution145_2 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Main.java
data_struct_study/src/stack_problem/Main.java
package stack_problem; /** * 栈问题 * * JsonChao的栈核心题库:8题 */ public class Main { public static void main(String[] args) { } }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution144_2.java
data_struct_study/src/stack_problem/Solution144_2.java
package stack_problem; import java.util.ArrayList; import java.util.List; import java.util.Stack; /** * O(n) * O(h) */ public class Solution144_2 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution150.java
data_struct_study/src/stack_problem/Solution150.java
package stack_problem; /** * 150: * 1、运算的种类(+,-,*,/) * 2、字符串表达的数字种类(整数) */ public class Solution150 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/stack_problem/Solution_2.java
data_struct_study/src/stack_problem/Solution_2.java
package stack_problem; import java.util.Stack; /** * 题目描述:请写一个整数计算器,支持加减乘三种运算和括号。 * * (2*(3-4))*5:不断递归,先计算最里面括号的值,并保存在栈中,然后再计算外面括号的。 * 1.用栈保存各部分计算的和 * 2.遍历表达式 * 3.遇到数字时继续遍历求这个完整的数字的值 * 4.遇到左括号时递归求这个括号里面的表达式的值 * 5.遇到运算符时或者到表达式末尾时,就去计算上一个运算符并把计算结果push进栈,然后保存新的运算符 * 如果是+,不要计算,push进去 * 如果是-,push进去负的当前...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/LinkedList_problem/Solution148.java
data_struct_study/src/LinkedList_problem/Solution148.java
package LinkedList_problem; /** * 排序链表:【merge sort + Floyd】 */ public class Solution148 { public ListNode sortList(ListNode head){ if (head==null||head.next==null) return head; ListNode fast = head.next; ListNode slow = head; while (fast!=null && fast.next!=null){ fas...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false
JsonChao/Awesome-Algorithm-Study
https://github.com/JsonChao/Awesome-Algorithm-Study/blob/f1c886eabf744b69e72a0b0a64b348032b439037/data_struct_study/src/LinkedList_problem/Solution_4_2.java
data_struct_study/src/LinkedList_problem/Solution_4_2.java
package LinkedList_problem; import java.util.ArrayList; import java.util.List; /** * 判断链表是否是一个回文结构 * * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution_4_2 { // 2、动态数组(ArrayList) + 双指针解法 public boolean isPail(ListNode head) { // 1、创建一个动态数组,并将链表中的节点都放入里面 List<Integer> list = new ArrayLis...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false