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/array_problem/Solution54.java
data_struct_study/src/array_problem/Solution54.java
package array_problem; /** * 螺旋矩阵 */ public class Solution54 { }
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/array_problem/Solution151.java
data_struct_study/src/array_problem/Solution151.java
package array_problem; public class Solution151 { }
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/array_problem/Solution557.java
data_struct_study/src/array_problem/Solution557.java
package array_problem; public class Solution557 { }
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/array_problem/Solution3_3.java
data_struct_study/src/array_problem/Solution3_3.java
package array_problem; /** * l 每次可以向前飞跃,而不仅仅是 +1,以确保滑动窗口中不存在重复的字符串, * 但为了获得这个飞跃值,每次都要遍历一次当前滑动窗口的大小。 * * 时间换空间: * 时间复杂度:O(r-l+1) * len(s)) * 空间复杂度:O(1) */ public class Solution3_3 { // 时间换空间的解法:时间复杂度:O(len(s)) * O(r-l+1),空间复杂度:O(1) public int lengthOfLongestSubstring(String s) { // 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/array_problem/Solution5.java
data_struct_study/src/array_problem/Solution5.java
package array_problem; /** * 最长回文子串:注意要分奇偶情况分别讨论。 */ public class Solution5 { public String longestPalindrome(String s) { if (s==null||s.length()<1) return ""; int maxLen=0, id=-1; for(int i=0; i<s.length(); i++){ int len1=expand(s,i,i); int len2=expand(s,i,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/array_problem/Solution4.java
data_struct_study/src/array_problem/Solution4.java
package array_problem; public class Solution4 { }
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/array_problem/Solution345.java
data_struct_study/src/array_problem/Solution345.java
package array_problem; //https://leetcode-cn.com/problems/reverse-vowels-of-a-string/:反转字符串中的元音字母 import java.util.Arrays; import java.util.HashSet; /** * 编写一个函数,以字符串作为输入,反转该字符串中的元音字母。 * * 示例 1: * * 输入: "hello" * 输出: "holle" * 示例 2: * * 输入: "leetcode" * 输出: "leotcede" * 说明: * 元音字母不包含字母"y"。 * * (元音aeiou)...
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/array_problem/Solution209.java
data_struct_study/src/array_problem/Solution209.java
package array_problem; /** * 滑动窗口 209: * 1、什么叫子数组? * 2、如果没有解怎么办?返回0 * 3、暴力解:遍历所有的连续子数组[i...j],计算其和 sum,验证 sum >= s,时间复杂度 O(n^3) * 暴力解的问题:大量的重复运算。 * 4、滑动窗口 nums[l...r] 时间 O(n),空间 O(1) */ 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/array_problem/Solution27.java
data_struct_study/src/array_problem/Solution27.java
package array_problem; //https://leetcode-cn.com/problems/remove-element/:移除元素 /** * 给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。 * * 不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 * * 元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。 * *   * * 示例 1: * * 给定 nums = [3,2,2,3], val = 3, * * 函数应该返回新的长度 2, 并且 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/array_problem/Solution695.java
data_struct_study/src/array_problem/Solution695.java
package array_problem; public class Solution695 { private int m, n; private int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; public int maxAreaOfIsland(int[][] grid) { if (grid == null || grid.length == 0) { return 0; } m = grid.length; n = grid[0].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/array_problem/Solution3.java
data_struct_study/src/array_problem/Solution3.java
package array_problem; /** * 3: * 1、字符集?只有字母?数字+字母?ASCLL? * 2、大小写是否敏感? * * 滑动窗口 * 时间复杂度:O(len(s)) * 空间复杂度:O(len(charset)) */ public class Solution3 { // 时间复杂度为 O(len(s)),空间复杂度为 O(len(charset)) public int lengthOfLongestSubstring(String s) { // 1、初始化一个存储ascill字符集的数组 int[] fre...
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/array_problem/Solution88.java
data_struct_study/src/array_problem/Solution88.java
package array_problem; /** * 给你两个有序整数数组 nums1 和 nums2,请你将 nums2 合并到 nums1 中,使 nums1 成为一个有序数组。 * 说明: 初始化 nums1 和 nums2 的元素数量分别为 m 和 n。 * 你可以假设 nums1 有足够的空间(空间大小大于或等于 m + n)来保存 nums2 中的元素。 *   * 示例: * 输入: * nums1 = [1,2,3,0,0,0], m = 3 * nums2 = [2,5,6], n = 3 * 输出: [1,2,2,3,5,6] */ public class Solutio...
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/array_problem/Solution283.java
data_struct_study/src/array_problem/Solution283.java
package array_problem; import java.util.ArrayList; /** * O(n) * O(n) */ public class Solution283 { public void moveZeroes(int[] nums) { ArrayList<Integer> noZeroList = new ArrayList<>(); for (int i = 0; i < nums.length; i++) { if (nums[i] != 0) { noZeroList.add(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/array_problem/Solution_3.java
data_struct_study/src/array_problem/Solution_3.java
package array_problem; import java.util.HashSet; /** * 原地哈希,把数组中取值在1到n的数放到对应的位置, * 比如1放到0的位置,2放到1的位置,……n放到n-1的位置, * 然后遍历重置后的数组,若i下标位置不是i+1,则i+1就是 * 那个最小的正整数,若1到n位置都对的上,说明最小的正整数是n+1。 * * 所谓原地哈希就是对数组中的元素,直接将其映射(也就是交换)到哈希函数计算出来的数组位置上。 * 本题要找的是第一个缺失的正整数,那么可以使用hash(i) = a[i] - 1这样一个哈希函数, * 比如对于数组2,3,1,5,-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/array_problem/Solution238.java
data_struct_study/src/array_problem/Solution238.java
package array_problem; import java.util.Arrays; /** * 除自身以外数组的乘积: 对于每一个元素而言,左边的所有元素 * 乘以右边的所有元素就能得到答案。注意,两次循环不能合并! */ public class Solution238 { public int[] productExceptSelf(int[] nums) { int n = nums.length; int[] product = new int[n]; Arrays.fill(product, 1); int left = 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/array_problem/Solution3_4.java
data_struct_study/src/array_problem/Solution3_4.java
package array_problem; import java.util.Arrays; /** * 3: * 1、字符集?只有字母?数字+字母?ASCLL? * 2、大小写是否敏感? * * 滑动窗口 * 时间复杂度:O(len(s)) * 空间复杂度:O(len(charset)) */ public class Solution3_4 { // 滑动窗口 + 优化:使用记录上一次滑动窗口右边界下标的数组,以实现找到重复元素时左边界的飞跃 // 时间复杂度:O(len(s)) 空间复杂度:O(len(charset)) public int lengthOf...
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/array_problem/Main.java
data_struct_study/src/array_problem/Main.java
package array_problem; /** * 什么是算法面试? * 1、不代表能够"正确"回答每一个算法问题,但是合理的思考方向其实更重要, * 也是正确完成算法面试的前提。 * 2、算法面试优秀并不意味着技术面试优秀,而技术面试优秀也并不意味着能够拿到 Offer。 * 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/array_problem/Solution8.java
data_struct_study/src/array_problem/Solution8.java
package array_problem; public class Solution8 { }
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/array_problem/Solution16.java
data_struct_study/src/array_problem/Solution16.java
package array_problem; 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/array_problem/Solution215.java
data_struct_study/src/array_problem/Solution215.java
package array_problem; /** * 在未排序的数组中找到第 k 个最大的元素。请注意,你需要找的是数组排序后 * 的第 k 个最大的元素,而不是第 k 个不同的元素。 * * 示例 1: * 输入: [3,2,1,5,6,4] 和 k = 2 * 输出: 5 * 示例 2: * * 输入: [3,2,3,1,2,4,5,5,6] 和 k = 4 * 输出: 4 * 说明: * * 你可以假设 k 总是有效的,且 1 ≤ k ≤ 数组的长度。 * * 1、排序 * O(nlogn) * O(1) * 2、堆排序:空间换时间 * O(nlogk) * O(k) * 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/array_problem/Solution14.java
data_struct_study/src/array_problem/Solution14.java
package array_problem; public class Solution14 { }
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/array_problem/Solution_2.java
data_struct_study/src/array_problem/Solution_2.java
package array_problem; /** * 多数投票问题,可以利用 Boyer-Moore 投票算法 * 来解决这个问题,使得时间复杂度为 O(n)。 * * 使用 cnt 来统计一个元素出现的次数,当遍历到的元素和统计元素相等时, * 令 cnt++,否则令 cnt--。如果前面查找了 i 个元素,且 cnt == 0, * 说明前 i 个元素没有 majority,或者有 majority,但是出现的次数 * 少于 i / 2 ,因为如果多于 i / 2 的话 cnt 就一定不会为 0 。 * 此时剩下的 n - i 个元素中,majority 的数目依然多于 (n - i) / 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/array_problem/Solution885.java
data_struct_study/src/array_problem/Solution885.java
package array_problem; public class Solution885 { }
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/array_problem/Solution60.java
data_struct_study/src/array_problem/Solution60.java
package array_problem; public class Solution60 { }
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/array_problem/Solution75_2.java
data_struct_study/src/array_problem/Solution75_2.java
package array_problem; /** * 三路快排的思想 * O(n) * O(1) */ public class Solution75_2 { public void sortColors(int[] nums) { // 1、[0, zero] 存储0 int zero = -1; // 2、[two, nums.length -1] 存储2 int two = nums.length; // 3、0,2指针往中间靠,最后中间剩下的就是1 // 注意 i < two,遍历的区间会随着尾部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/array_problem/Solution3_2.java
data_struct_study/src/array_problem/Solution3_2.java
package array_problem; /** * 3: * 1、字符集?只有字母?数字+字母?ASCLL? * 2、大小写是否敏感? * * 滑动窗口 * 时间复杂度:O(len(s)) * 空间复杂度:O(len(charset)) */ public class Solution3_2 { // 时间复杂度:O(len(s)),空间复杂度:O(charset) public int lengthOfLongestSubstring(String s) { // 1、初始化一个存储ascill字符集的数组用来记录元素的出现频次 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/array_problem/BinarySearch.java
data_struct_study/src/array_problem/BinarySearch.java
package array_problem; /** * 二分搜索:[0, n-1] 区间搜索版 */ public class BinarySearch { public static int binarySearch(Comparable[] arr, int n, Comparable target){ int l = 0; int r = n - 1; while (l <= r) { int mid = l + (r - l) / 2; if (arr[mid].compareTo(target) == 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/red_black_tree/RBTree.java
data_struct_study/src/red_black_tree/RBTree.java
package red_black_tree; import avl.FileOperation; import java.util.ArrayList; /** * 算法导论中给出的5条红黑树的定义太生硬,并不能让人理解到底什么才是红黑树。 * 而算法4的作者 Robert Sedgewick 是红黑树的发明人之一,而他正是现代计算机科学之父 * Donald Knuth 的弟子,可以挑战下 Donald Knuth 的两大著作:《计算机编程的艺术》 * * 红黑树与2-3树的等价性。理解了2-3树,对我们理解红黑树与B类树有巨大帮助。 * * 2-3树: * 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/red_black_tree/Main2.java
data_struct_study/src/red_black_tree/Main2.java
package red_black_tree; import avl.AVLTree; import avl.BST; import java.util.ArrayList; import java.util.Random; public class Main2 { public static void main(String[] args) { // int n = 20000000; int n = 20000000; Random random = new Random(n); ArrayList<Integer> testData = new...
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/red_black_tree/Main.java
data_struct_study/src/red_black_tree/Main.java
package red_black_tree; import avl.AVLTree; import avl.BST; import avl.FileOperation; import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.println("Pride and Prejudice"); ArrayList<String> words = new ArrayList<>(); if(FileOperation.readFi...
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/red_black_tree/Main3.java
data_struct_study/src/red_black_tree/Main3.java
package red_black_tree; import avl.AVLTree; import java.util.ArrayList; import java.util.Random; public class Main3 { public static void main(String[] args) { int n = 20000000; ArrayList<Integer> testData = new ArrayList<>(n); for(int i = 0 ; i < n ; i ++) testData.add(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/binary_search_tree/BST.java
data_struct_study/src/binary_search_tree/BST.java
package binary_search_tree; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; /** * 树结构本身是一种天然的的组织结构,用树存储数据能更加高效地搜索。 * * 二叉树:和链表一样,动态数据结构。 * 1)、对于每一个节点,最多能分成2个节点,即左孩子和右孩子。 * 2)、没有孩子的节点称为叶子节点。 * 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/binary_search_tree/Main.java
data_struct_study/src/binary_search_tree/Main.java
package binary_search_tree; import java.util.ArrayList; import java.util.Random; public class Main { public static void main(String[] args) { // int[] arr = {5, 3, 8, 2, 9, 7}; // BST<Integer> bst = new BST<>(); // for (int value : arr) { // bst.add(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/heap_and_priority_queue/PriorityQueue.java
data_struct_study/src/heap_and_priority_queue/PriorityQueue.java
package heap_and_priority_queue; import queue.Queue; /** * 用最大堆实现的优先队列 * * 在 100 万个元素中选取前 100 个元素? * * 使用优先队列,维护当前看到的前 100 个元素,需要使用最小堆,也可以使用最大堆(将常规的优先级定义取反即可) * * 使用 TreeMap 求频次 * * @param <E> */ public class PriorityQueue<E extends Comparable<E>> implements Queue<E> { private MaxHeap<E> maxHeap; ...
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/heap_and_priority_queue/Solution2.java
data_struct_study/src/heap_and_priority_queue/Solution2.java
package heap_and_priority_queue; import java.util.PriorityQueue; import java.util.TreeMap; /** * 1、最简单的思路:扫描一遍统计概率,排序找到前k个出现频率最高的元素。时间复杂度:O(nlogn) * 2、使用优先队列不停地维护我们能找到的前k个出现频率最高的元素。时间复杂度:O(nlogk) * * Java 的 PriorityQueue 内部是最小堆 * d 叉堆:d-ary heap * 常规堆的缺陷:只能看到堆首的元素。 * 索引堆:保存元素与之对应的索引。 * 二项堆 * 斐波那契堆 * 普通队列、优...
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/heap_and_priority_queue/MaxHeap.java
data_struct_study/src/heap_and_priority_queue/MaxHeap.java
package heap_and_priority_queue; import array.Array; /** * 向堆中添加元素(上浮,Sift Up) O(logn) * 从堆中取出最大元素(下沉,Sift Down) O(logn) * * replace:取出最大元素后,放入一个新元素。 * 实现1:可以先 extractMax,再 add,两次 O(logn)操作。 * 实现2:可以直接将堆顶元素替换以后 Sift Down,一次 O(logn)操作。 * * 将 n 个元素插入一个空堆中,算法复杂度为 O(nlogn)。 * heapify(堆化):算法复杂度为 O(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/heap_and_priority_queue/Solution.java
data_struct_study/src/heap_and_priority_queue/Solution.java
package heap_and_priority_queue; /// 347. Top K Frequent Elements /// https://leetcode.com/problems/top-k-frequent-elements/description/ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.TreeMap; public class Solution { private class Array<E> { private E[] dat...
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/heap_and_priority_queue/Main.java
data_struct_study/src/heap_and_priority_queue/Main.java
package heap_and_priority_queue; import java.util.Arrays; import java.util.Random; /** * 普通队列:先进先出,后进后出 * 优先队列:出队顺序和入队顺序无关,和优先级相关 * * 应用场景:操作系统的任务调度,动态 选择优先级最高的任务进行处理。医生和患者之间的关系。 * * 优先队列底层实现 入队 出队 * 普通线性结构 O(1) O(n) * 顺序线性结构 O(n) O(n) * 堆 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/sort_problem/HeapSort.java
data_struct_study/src/sort_problem/HeapSort.java
package sort_problem; /** * 大顶堆实现堆排序: * 1、构建初始堆,将待排序列构成一个大顶堆:序列对应一个完全二叉树;从最后一个分支结点(n/2)开始, * 到根(1)为止,依次对每个分支结点进行下沉,以便形成以每个分支结点为根的堆,当最后对树根结点进行 * 调整后,整个树就变成了一个堆。 * 2、将堆顶元素与堆尾元素交换,并从待排序列中移除堆尾元素。 * 3、使用下沉操作下沉堆顶元素以重新构建大顶堆。 * 4、重复2~3,直到待排序列中只剩下一个元素(即堆顶元素)。 * * 下沉操作: * 1、仅当当前节点有左子节点时进入while循环体。 * 2、设立下沉后的位置为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/sort_problem/Bubble.java
data_struct_study/src/sort_problem/Bubble.java
package sort_problem; /** * 从左到右不断交换相邻逆序的元素,在一轮循环之后,可以让未排序的最大元素上浮到右侧。 * 优化:在一轮循环中,如果没有发生交换,那么说明数组已经是有序的,此时可以直接退出。 */ public class Bubble<T extends Comparable<T>> extends Sort<T> { @Override public void sort(T[] nums) { int N = nums.length; boolean isSorted = false; for (int i = 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/sort_problem/Shell.java
data_struct_study/src/sort_problem/Shell.java
package sort_problem; /** * 对于大规模的数组,插入排序很慢,因为它只能交换相邻的元素,每次只能 * 将逆序数量减少 1。希尔排序的出现就是为了解决插入排序的这种局限性, * 它通过交换不相邻的元素,每次可以将逆序数量减少大于 1。 * * 希尔排序使用插入排序对间隔 h 的序列进行排序。通过不断减小 h,最后 * 令 h=1,就可以使得整个数组是有序的。 * * 希尔排序的运行时间达不到平方级别,使用递增序列 1, 4, 13, 40, ... * 的希尔排序所需要的比较次数不会超过 N 的若干倍乘于递增序列的长度。 * 高级排序算法只会比希尔排序快两倍左右。 */ public ...
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/sort_problem/QuickSelection.java
data_struct_study/src/sort_problem/QuickSelection.java
package sort_problem; /** * 快速排序的 partition() 方法,会返回一个整数 j 使得 a[l..j-1] * 小于等于 a[j],且 a[j+1..h] 大于等于 a[j],此时 a[j] * 就是数组的第 j 大元素。 * 可以利用这个特性找出数组的第 k 个元素。该算法是线性级别的,假设每次 * 能将数组二分,那么比较的总次数为 (N+N/2+N/4+..),直到找到第 k * 个元素,这个和显然小于 2N。 */ public class QuickSelection<T extends Comparable<T>> extends Sort<T>{ public...
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/sort_problem/ThreeWayQuickSort.java
data_struct_study/src/sort_problem/ThreeWayQuickSort.java
package sort_problem; /** * 快排改进: * 1、切换到插入排序: * 因为快速排序在小数组中也会递归调用自己,对于小数组,插入排序比 * 快速排序的性能更好,因此在小数组中可以切换到插入排序。 * * 2、三数取中: * 最好的情况下是每次都能取数组的中位数作为切分元素,但是计算中位数 * 的代价很高。一种折中方法是取 3 个元素,并将大小居中的元素作为切分元素。 * * 3、三向切分: * 对于有大量重复元素的数组,可以将数组切分为三部分,分别对应小于、等于和大于切分元素。 * 三向切分快速排序对于有大量重复元素的随机数组可以在线性时间内完成排序。 */ public cla...
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/sort_problem/MergeSort.java
data_struct_study/src/sort_problem/MergeSort.java
package sort_problem; /** * 思路:归并排序的思想是不断地将数组分成两部分,分别进行排序,然后归并起来, * 归并就是将数组中两个已排序的部分归并成一个。归并排序是稳定性算法。 * 时间复杂度:O(NlogN) * 空间复杂度:O(N) */ public class MergeSort<T extends Comparable<T>> extends Sort<T> { protected T[] aux; // 归并方法:归并方法将数组中两个已经排序的部分归并成一个 protected void merge(T[] nums, int l, int m, 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/sort_problem/QuickSort.java
data_struct_study/src/sort_problem/QuickSort.java
package sort_problem; import java.util.Arrays; import java.util.Collections; import java.util.List; /** * 归并排序将数组分为两个子数组分别排序,并将有序的子数组归并使得整个数组排序; * 快速排序通过一个切分元素将数组分为两个子数组,左子数组小于等于切分元素, * 右子数组大于等于切分元素,将这两个子数组排序也就将整个数组排序了。 * * 快速排序是原地排序,不需要辅助数组,但是递归调用需要辅助栈。 * 快速排序最好的情况下是每次都正好将数组对半分,这样递归调用次数才是最少的。 * 这种情况下比较次数为 CN=...
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/sort_problem/Selection.java
data_struct_study/src/sort_problem/Selection.java
package sort_problem; /** * 从数组中选择最小的元素,将它与数组的第一个元素交换位置。再从数组剩下的元素中 * 选择出最小的元素,将它与数组的第二个元素交换位置。不断进行这样的操作,直到将整个数组排序。 * * 选择排序需要 ~N2/2 次比较和 ~N 次交换,它的运行时间与输入无关,这个特点 * 使得它对一个已经排序的数组也需要这么多的比较和交换操作。 */ public class Selection<T extends Comparable<T>> extends Sort<T> { @Override public void sort(T[] 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/sort_problem/Insertion.java
data_struct_study/src/sort_problem/Insertion.java
package sort_problem; /** * 每次都将当前元素插入到左侧已经排序的数组中,使得插入之后左侧数组依然有序。 * * 对于数组 {3, 5, 2, 4, 1},它具有以下逆序:(3, 2), (3, 1), (5, 2), * (5, 4), (5, 1), (2, 1), (4, 1),插入排序每次只能交换相邻元素, * 令逆序数量减少 1,因此插入排序需要交换的次数为逆序数量。 * * 插入排序的时间复杂度取决于数组的初始顺序,如果数组已经部分有序了, * 那么逆序较少,需要的交换次数也就较少,时间复杂度较低。 * * 平均情况下插入排序需要 ~N2/4 比较以及 ~N2/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/sort_problem/Sort.java
data_struct_study/src/sort_problem/Sort.java
package sort_problem; /** * 待排序的元素需要实现 Java 的 Comparable 接口,该接口有 compareTo() 方法,可以用它来判断两个元素的大小关系。 * 使用辅助函数 less() 和 swap() 来进行比较和交换的操作,使得代码的可读性和可移植性更好。 * 排序算法的成本模型是比较和交换的次数。 * * 算法 稳定性 时间复杂度 空间复杂度 备注 * 选择排序 × N2 1 * 冒泡排序 √ N2 1 * 插入排序 √ N ~ N2 1 时间复杂度和初始顺序有关 * 希尔排序 × N 的若干倍乘于递增序列的长度 1 改进版插入排序 * 快速排序 × NlogN ...
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/union_find/UnionFind2.java
data_struct_study/src/union_find/UnionFind2.java
package union_find; public class UnionFind2 implements UF { /** * parent[i] 表示第i个元素所属集合中的根节点。 */ private int[] parent; public UnionFind2(int size) { parent = new int[size]; // 每一个元素都是一个单独的集合,也是一棵树的根节点,特征为自己指向自己 for (int i = 0; i < parent.length; i++) { paren...
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/union_find/UF.java
data_struct_study/src/union_find/UF.java
package union_find; public interface UF { int getSize(); boolean isConnected(int p, int q); void unionElements(int p, int q); }
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/union_find/UnionFind1.java
data_struct_study/src/union_find/UnionFind1.java
package union_find; public class UnionFind1 implements UF { private int[] id; public UnionFind1(int size) { id = new int[size]; for (int i = 0; i < size; i++) { id[i] = i; } } @Override public int getSize() { return id.length; } private int 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/union_find/UnionFind4.java
data_struct_study/src/union_find/UnionFind4.java
package union_find; /** * 基于 rank(深度排名,并不完全表示数的深度) 的优化,比基于 size 的优化要更合理,合并后得到的 h 在某些情况下要更小。 */ public class UnionFind4 implements UF { /** * parent[i] 表示第i个元素所属集合中的根节点。 */ private int[] parent; /** * sz[i] 表示以i为根的集合的深度 */ private int[] rank; public UnionFind4(int size) { ...
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/union_find/UnionFind5.java
data_struct_study/src/union_find/UnionFind5.java
package union_find; /** * 在 find 方法加上路径压缩。 * 基于 rank(深度排名,并不完全表示数的深度) 的优化, * 比基于 size 的优化要更合理,合并后得到的 h 在某些情况下要更小。 */ public class UnionFind5 implements UF { /** * parent[i] 表示第i个元素所属集合中的根节点。 */ private int[] parent; /** * sz[i] 表示以i为根的集合的深度 */ private int[] rank; public ...
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/union_find/UnionFind3.java
data_struct_study/src/union_find/UnionFind3.java
package union_find; /** * 基于 size 的优化,避免形成类似链表的结构,导致 O(h)过大。 */ public class UnionFind3 implements UF { /** * parent[i] 表示第i个元素所属集合中的根节点。 */ private int[] parent; /** * sz[i] 表示以i为根的集合中的元素个数 */ private int[] sz; public UnionFind3(int size) { parent = new int[size];...
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/union_find/Main.java
data_struct_study/src/union_find/Main.java
package union_find; /** * 并查集:由孩子指向父亲,通常用来解决连接问题,最适合合并与查询是相互交替动态进行的请求。 * * 应用场景: * 1、网络中节点间的连接状态,网络是一个抽象的概念,用户之间也可以形成网络。 * 2、数学中的集合类实现,求集合中的并集。 * * 连接问题和路径问题 类比为 堆和顺序表,我们只需要判断它是不是连接的或是最大、最小的元素。 * * 同一个集合 id 就属于一个集合,就表示是相连的。 * * Quick Find (使用数组模拟操作并查集的过程): * find 与 isConnected 时间复杂度 O(1),unionElement...
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/union_find/UnionFind6.java
data_struct_study/src/union_find/UnionFind6.java
package union_find; /** * 递归的路径压缩方式,相比非递归的路径压缩性能要稍微差一点。 * 时间复杂度 O(log*n) = { 0 if(n<=1) 1+log*(logn) if(n>1)},可以认作近乎是O(1)级别的。 * 在 find 方法加上路径压缩。 * 基于 rank(深度排名,并不完全表示数的深度) 的优化, * 比基于 size 的优化要更合理,合并后得到的 h 在某些情况下要更小。 */ public class UnionFind6 implements UF { /** * parent[i] 表示第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/backstracking_problem/Solution93.java
data_struct_study/src/backstracking_problem/Solution93.java
package backstracking_problem; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * 递归与回溯 * * 题目描述:给定一个只包含数字的字符串,复原它并返回所有可能的 IP 地址格式。 * 有效的 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0), * 整数之间用 '.' 分隔。 * * 时间复杂度:O(3 ^ SEG_COUNT * ∣s∣) * 空间复杂度:O(SEG_COUNT) */ class Solution93...
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/backstracking_problem/Solution401.java
data_struct_study/src/backstracking_problem/Solution401.java
package backstracking_problem; public class Solution401 { }
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/backstracking_problem/main.java
data_struct_study/src/backstracking_problem/main.java
package backstracking_problem; /** * 递归与回溯 * * JsonChao的递归与回溯核心题库:21题 */ 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/backstracking_problem/Solution200.java
data_struct_study/src/backstracking_problem/Solution200.java
package backstracking_problem; /** * O(m * n) * O(m * n) * 岛屿数量: 求连通分支个数【dfs】和 【union find】。使用unionfind的原理为: * 顶点数-最小生成树连线数=连通分支个数。 */ public class Solution200 { private int[][] d = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; private int m, n; private boolean[][] visited; public int numIslands(char[][] ...
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/backstracking_problem/Solution52.java
data_struct_study/src/backstracking_problem/Solution52.java
package backstracking_problem; /** * 回溯法时经典人工智能的基础 * 1、剪枝 * 2、快速判断不合法的情况: * 竖向:col[i] 表示第i列被占用 * 对角线1:dia1[i] 表示第i对角线1被占用—— 2*n-1个 i+j。对角线相加 * 对角线2:dia2[i] 表示第i对角线2被占用—— 2*n-1个 i+j+n-1。对角线相减 */ public class Solution52 { }
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/backstracking_problem/Solution51.java
data_struct_study/src/backstracking_problem/Solution51.java
package backstracking_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedList; import java.util.List; /** * 回溯法是经典人工智能的基础 * 1、剪枝 * 2、快速判断不合法的情况: * 竖向:col[i] 表示第i列被占用 * 对角线1:dia1[i] 表示第i对角线1被占用—— 2*n-1个 i+j。对角线相加 * 对角线2:dia2[i] 表示第i对角线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/backstracking_problem/Solution17.java
data_struct_study/src/backstracking_problem/Solution17.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; /** * 递归与回溯 * 树形问题 17: * 1、字符串的合法性 * 2、空字符串(null) * 3、多个解的顺序(无) * 4、digits 是数字字符串,s(digits) 是digits所能代表的字母字符串, * s(digital[0...n-1]) * = letter(digital[0]) + letter(digital[1...n-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/backstracking_problem/Solution46.java
data_struct_study/src/backstracking_problem/Solution46.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; /** * 排列问题 * 时间复杂度:O(n*n!) * 空间复杂度:O(n) */ public class Solution46 { public List<List<Integer>> permute(int[] nums) { // 1、创建一个组合嵌套列表 & 组合列表 & 记录已访问元素的数组 List<List<Integer>> permutes = new 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/backstracking_problem/Solution90.java
data_struct_study/src/backstracking_problem/Solution90.java
package backstracking_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Solution90 { public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> subsets = new ArrayList<>(); List<Integer> tempSubset = new ArrayList<>(); 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/backstracking_problem/Solution78.java
data_struct_study/src/backstracking_problem/Solution78.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; /** * 子集 */ public class Solution78 { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> subsets = new ArrayList<>(); List<Integer> tempSubset = new ArrayList<>(); // 统计不同子集的大小 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/backstracking_problem/Solution131.java
data_struct_study/src/backstracking_problem/Solution131.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; /** * 递归与回溯 */ public class Solution131 { public List<List<String>> partition(String s) { List<List<String>> partitions = new ArrayList<>(); List<String> tempPartition = new ArrayList<>(); backTracing(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/backstracking_problem/Solution417.java
data_struct_study/src/backstracking_problem/Solution417.java
package backstracking_problem; /** * floodfill 洪水填充算法——深度优先遍历 */ public class Solution417 { }
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/backstracking_problem/Solution216.java
data_struct_study/src/backstracking_problem/Solution216.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; public class Solution216 { public List<List<Integer>> combinationSum3(int k, int n) { List<List<Integer>> combinations = new ArrayList<>(); List<Integer> tempCombination = new ArrayList<>(); backtracking(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/backstracking_problem/Solution47.java
data_struct_study/src/backstracking_problem/Solution47.java
package backstracking_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * 排列问题 * 时间复杂度:O(n*n!) * 空间复杂度:O(n) */ public class Solution47 { public List<List<Integer>> permuteUnique(int[] nums) { // 1、创建一个嵌套排列列表 & 排列列表 & 记录已访问元素的数组 List<List<Integer>> permu...
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/backstracking_problem/Solution89.java
data_struct_study/src/backstracking_problem/Solution89.java
package backstracking_problem; public class Solution89 { }
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/backstracking_problem/Solution39.java
data_struct_study/src/backstracking_problem/Solution39.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; public class Solution39 { public List<List<Integer>> combinationSum(int[] candidates, int target) { List<List<Integer>> combinations = new ArrayList<>(); backtracking(new ArrayList<>(), combinations, 0, target, can...
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/backstracking_problem/Solution77.java
data_struct_study/src/backstracking_problem/Solution77.java
package backstracking_problem; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * 组合问题 * O(n^k) * O(k) */ public class Solution77 { private ArrayList<List<Integer>> res; public List<List<Integer>> combine(int n, int k) { res = new ArrayList<>(); if (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/backstracking_problem/Solution79.java
data_struct_study/src/backstracking_problem/Solution79.java
package backstracking_problem; /** * 二维平面上的回溯法 * O(m*n*m*n) * O(m*n) */ public class Solution79 { private int m; private int n; private int[][] d = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; private boolean[][] visited; public boolean exist(char[][] board, String word) { if (board == 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/backstracking_problem/Solution22.java
data_struct_study/src/backstracking_problem/Solution22.java
package backstracking_problem; import java.util.ArrayList; import java.util.List; /** * 括号生成:【递归】,分只能添加“(”,只能添加“)”,和有可以添加 * “(”又能添加“)”三种情况。注意“)”的个数时时刻刻不能超过“(”。 */ public class Solution22 { public List<String> generateParenthesis(int n) { add("", 0, 0, n); return list; } List<String> l...
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/backstracking_problem/Solution130.java
data_struct_study/src/backstracking_problem/Solution130.java
package backstracking_problem; /** * floodfill 洪水填充算法——深度优先遍历 */ public class Solution130 { int[][] d = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int m , n; public void solve(char[][] board) { if (board == null || board.length == 0) { return; } m = board.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/backstracking_problem/Solution37.java
data_struct_study/src/backstracking_problem/Solution37.java
package backstracking_problem; /** * 回溯法是经典人工智能的基础 * 1、剪枝 * 2、快速判断不合法的情况: * 竖向:col[i] 表示第i列被占用 * 对角线1:dia1[i] 表示第i对角线1被占用—— 2*n-1个 i+j。对角线相加 * 对角线2:dia2[i] 表示第i对角线2被占用—— 2*n-1个 i+j+n-1。对角线相减 */ public class Solution37 { }
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/backstracking_problem/Solution77_2.java
data_struct_study/src/backstracking_problem/Solution77_2.java
package backstracking_problem; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * 组合问题 * 1、回溯法解决组合问题的优化:剪枝,避免最后的重复运算。 * O(n^k) * O(k) */ public class Solution77_2 { private ArrayList<List<Integer>> res; public List<List<Integer>> combine(int n, int 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/backstracking_problem/Solution40.java
data_struct_study/src/backstracking_problem/Solution40.java
package backstracking_problem; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Solution40 { public List<List<Integer>> combinationSum2(int[] candidates, int target) { List<List<Integer>> combinations = new ArrayList<>(); List<Integer> tempCombination = ne...
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/trie/WordDictionary.java
data_struct_study/src/trie/WordDictionary.java
package trie; import java.util.TreeMap; class WordDictionary { public class Node { boolean isWord; TreeMap<Character, Node> next; public Node(boolean isWord) { this.isWord = isWord; next = new TreeMap<>(); } public Node() { this(false)...
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/trie/Trie3.java
data_struct_study/src/trie/Trie3.java
package trie; public class Trie3 { private class Node{ public boolean isWord; public Node[] next; public Node(boolean isWord){ this.isWord = isWord; next = new Node[26]; } public Node(){ this(false); } } private Node 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/trie/Trie206.java
data_struct_study/src/trie/Trie206.java
package trie; import java.util.TreeMap; class Trie206 { private class Node { boolean isWord; TreeMap<Character, Node> next; public Node(boolean isWord) { this.isWord = isWord; next = new TreeMap<>(); } public Node() { this(false); ...
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/trie/Trie2.java
data_struct_study/src/trie/Trie2.java
package trie; import java.util.HashMap; // 使用HashMap的Trie public class Trie2 { private class Node{ public boolean isWord; public HashMap<Character, Node> next; public Node(boolean isWord){ this.isWord = isWord; next = new HashMap<>(); } public No...
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/trie/MapSum.java
data_struct_study/src/trie/MapSum.java
package trie; import java.util.TreeMap; class MapSum { public class Node { public int value; public TreeMap<Character, Node> next; public Node(int value) { this.value = value; next = new TreeMap<>(); } public Node() { this(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/trie/Main.java
data_struct_study/src/trie/Main.java
package trie; import set.BSTSet; import set.FileOperation; import java.util.ArrayList; /** * Trie:字典树,前缀树,多叉树 * * 作用:专门为处理字符串而设计的 * * 字典与 Trie 的比较: * * 字典:如果有 n 个条目,使用平衡二叉树查询的复杂度为 O(logn),100万(2^20)的数据量其 logn 大概为 20。 * Trie:查询的时间复杂度为 O(w),w 为查询单词的的长度,大多数单词的长度小于10。 * * Trie 中每一个节点都有若干个指向下一个节点的指针,考虑不同的语言,不同的...
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/trie/Trie.java
data_struct_study/src/trie/Trie.java
package trie; import java.util.TreeMap; /** * Trie 的删除操作 * * Trie 的局限性:next 指针是 TreeMap 数据类型,key 值总数最多可以达到26种。 * 改进方式:使用压缩字典树 Compressed Trie * * 三分搜索树(Ternary Search Tree):时间换空间。 * * 后缀树 * * 子串查询算法:KMP、Boyer-Moore、Rabin-Karp。 * * 文件压缩实际上也算是一种字符串压缩。 * * 模式匹配:实现一个正则表达式引擎。 * * 编译原理:字符串应用很多。 * * DNA:超长...
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/Solution213.java
data_struct_study/src/dynamic_problem/Solution213.java
package dynamic_problem; public class Solution213 { public int rob(int[] nums) { if (nums == null || nums.length == 0) { return 0; } int n = nums.length; if (n == 1) { return nums[0]; } return Math.max(tryRob(nums, 0, n - 2), tryRob(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/Solution139.java
data_struct_study/src/dynamic_problem/Solution139.java
package dynamic_problem; import java.util.List; public class Solution139 { public boolean wordBreak(String s, List<String> wordDict) { int n = s.length(); boolean[] dp = new boolean[n + 1]; dp[0] = true; for (int i = 1; i <= n; i++) { for(String word:wordDict) { ...
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_6.java
data_struct_study/src/dynamic_problem/Solution198_6.java
package dynamic_problem; /** * DP:优化状态转移 */ public class Solution198_6 { public int rob(int[] nums) { int n = nums.length; if (n == 0) { return 0; } int[] memo = new int[n]; memo[n - 1] = nums[n - 1]; for (int i = n - 2; i >= 0; i--) { me...
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_4.java
data_struct_study/src/dynamic_problem/Solution198_4.java
package dynamic_problem; public class Solution198_4 { public int rob(int[] nums) { int n = nums.length; if (n == 0) { return 0; } int[] memo = new int[n]; for (int i = 1; i < n; i++) { for (int j = i; j >= 0; j--) { memo[i] = Math.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/Solution63.java
data_struct_study/src/dynamic_problem/Solution63.java
package dynamic_problem; public class Solution63 { }
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/Solution120.java
data_struct_study/src/dynamic_problem/Solution120.java
package dynamic_problem; public class Solution120 { }
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_2.java
data_struct_study/src/dynamic_problem/Solution343_2.java
package dynamic_problem; import array.Array; import java.util.Arrays; /** * 记忆化搜索 + 暴力搜索 * O(n ^ 2) * O(n) */ public class Solution343_2 { private int[] memo; public int integerBreak(int n) { if (n < 1) { throw new IllegalArgumentException("Illegal argument!"); } 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/Solution509.java
data_struct_study/src/dynamic_problem/Solution509.java
package dynamic_problem; /** * 递归 */ public class Solution509 { public int fib(int n) { if (n == 0) { return 0; } if (n == 1) { return 1; } return fib(n - 1) + fib(n - 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/Solution300_2.java
data_struct_study/src/dynamic_problem/Solution300_2.java
package dynamic_problem; import java.util.Arrays; /** * 记忆化搜索 + DP * 时间复杂度:O(n ^ 2) * 空间复杂度:O(n) */ public class Solution300_2 { public int lengthOfLIS(int[] nums) { // 1、异常处理:如果nums为0,则返回0 int n = nums.length; if (n == 0) { return 0; } // 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/Solution198_3.java
data_struct_study/src/dynamic_problem/Solution198_3.java
package dynamic_problem; import java.util.Arrays; /** * 记忆化搜索 * O(n ^ 2) * O(n) */ public class Solution198_3 { private int[] memo; public int rob(int[] nums) { memo = new int[nums.length]; Arrays.fill(memo, -1); return tryRob(nums, nums.length - 1); } private int tryRob...
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_3.java
data_struct_study/src/dynamic_problem/Solution70_3.java
package dynamic_problem; /** * 3、Dp + 循环只需记录前两个数的值 => 矩阵快速幂 or 推导公式可以优化时间到 O(logn) * 时间复杂度:O(n) * 空间复杂度:O(1) */ public class Solution70_3 { // 3、DP + 循环计算只依赖前两个值即可 // 时间复杂度:O(n), 空间复杂度:O(1) public int climbStairs(int n) { // 1、异常处理:n小于0抛出异常 if (n < 0) { throw new IllegalAr...
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.java
data_struct_study/src/dynamic_problem/Solution198.java
package dynamic_problem; import java.util.Arrays; /** * 状态的定义和状态转移 * 1、暴力解法:检查所有房子的组合,对每一个组合,检查是否有相邻的房子,如果没有,记录其价值。找最大值。O((2^n)*n) * 2、注意其中对状态的定义: * 函数的定义:考虑偷取[x...n-1]范围内的房子。 * 根据对状态的定义,决定状态转移方程: * f(0) = max{v(0) + f(2), v(1) + f(3) , ... , v(n-3) + f(n-1) ,v(n-2),v(n-1)} */ public ...
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_3.java
data_struct_study/src/dynamic_problem/Solution509_3.java
package dynamic_problem; import java.util.Arrays; /** * 动态规划(DP)+ 记忆化搜索 */ public class Solution509_3 { public int fib(int n) { if (n == 0) { return 0; } int[] memo = new int[n + 1]; Arrays.fill(memo, -1); memo[0] = 0; memo[1] = 1; 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/dynamic_problem/Solution354.java
data_struct_study/src/dynamic_problem/Solution354.java
package dynamic_problem; public class Solution354 { }
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false