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/LinkedList_problem/Solution142.java
data_struct_study/src/LinkedList_problem/Solution142.java
package LinkedList_problem; /** * 环形链表 II:快慢指针+Floyd算法。 */ public class Solution142 { // 1、fast走的步数是slow步数的2倍:f=2s、fast比slow多走了n个环的长度:f=s+nb => s = nb // 2、走a+nb步一定是在环的入口 // 3、slow再走a = 入口 = head走到入口 = a // 4、由3得出,起始距离入口 = 第一次相遇位置 + a,所以,此时再次相遇时的节点即为环的入口节点 public ListNode detectCycle(ListNode he...
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/Solution141.java
data_struct_study/src/LinkedList_problem/Solution141.java
package LinkedList_problem; /** * 判断链表是否有环 */ public class Solution141 { // 双指针:时间复杂度O(n), 空间复杂度O(1) public boolean hasCycle(ListNode head) { // 1、异常处理:如果头结点为null,则返回false // 为什么不判断head.next为null?因为1个节点也可以构成环形链表,即自己指向自己 if (head == null) { return 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/LinkedList_problem/Solution328.java
data_struct_study/src/LinkedList_problem/Solution328.java
package LinkedList_problem; public class Solution328 { public ListNode oddEvenList(ListNode head) { if (head == null) { return null; } ListNode odd = head, even = head.next, evenHead = even; while (even != null && even.next != null) { odd.next = odd.next.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/LinkedList_problem/Solution2.java
data_struct_study/src/LinkedList_problem/Solution2.java
package LinkedList_problem; /** * 2: * 1、数字之外是否有前置的0。(除0以外,没有前置0) * 2、负数(不是)。 * * prev ListNode */ public class Solution2 { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode prev=new ListNode(0), l=prev; int carry=0; while(l1!=null||l2!=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/LinkedList_problem/Solution143.java
data_struct_study/src/LinkedList_problem/Solution143.java
package LinkedList_problem; public class Solution143 { }
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/Solution160.java
data_struct_study/src/LinkedList_problem/Solution160.java
package LinkedList_problem; public class Solution160 { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { ListNode l1 = headA, l2 = headB; while (l1 != l2) { l1 = (l1 == null) ? headB : l1.next; l2 = (l2 == null) ? headA : l2.next; } retu...
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_4.java
data_struct_study/src/LinkedList_problem/Solution_4_4.java
package LinkedList_problem; /** * 快慢指针: * 时间复杂度:O(n), 空间复杂度:O(1) */ public class Solution_4_4 { // 4、快慢指针解法:先使用快慢指针找到前半个链表的尾节点,然后翻转后半个部分链表, // 最后再使用双指针依次比较对应元素,如果不同则返回false,记得返回前需要还原链表 // 时间复杂度O(n), 空间复杂度O(1) public boolean isPail(ListNode head) { // 1、如果只有0或1个节点,则说明是回文结构 if (head ...
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/Solution237.java
data_struct_study/src/LinkedList_problem/Solution237.java
package LinkedList_problem; /** * O(1) * O(1) */ public class Solution237 { public void deleteNode(ListNode node) { if (node == null || node.next == null) { throw new IllegalArgumentException("node must not null and node must not tail node!"); } node.val = node.next.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/LinkedList_problem/Solution_4_3.java
data_struct_study/src/LinkedList_problem/Solution_4_3.java
package LinkedList_problem; /** * 判断链表是否是一个回文结构 * * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution_4_3 { private ListNode frontPointer; // 3、递归:currentNode 指针是先到尾节点,由于递归的特性再从后往前进行比较。 // frontPointer 是递归函数外的指针。若 currentNode.val != frontPointer.val // 则返回 false。反之,frontPointer 向前移动并返回 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/LinkedList_problem/Solution24.java
data_struct_study/src/LinkedList_problem/Solution24.java
package LinkedList_problem; /** * (p、node1、node2、(next) => 复杂的穿针引线) * O(n) * O(1) */ public class Solution24 { public ListNode swapPairs(ListNode head) { ListNode dummyHead = new ListNode(0); dummyHead.next = head; ListNode p = dummyHead; while (p.next != null && p.next.next...
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.java
data_struct_study/src/LinkedList_problem/Solution_4.java
package LinkedList_problem; import java.util.ArrayDeque; import java.util.Deque; /** * 判断链表是否是一个回文结构 * * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution_4 { // 1、Java双端队列解法:利用Deque的pollFirst和pollLast方法来比较, // 时间复杂度:O(n), 空间复杂度:O(n) public boolean isPail(ListNode head) { // 1、如果链表节点数为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/LinkedList_problem/Solution_1.java
data_struct_study/src/LinkedList_problem/Solution_1.java
package LinkedList_problem; /** * 两个链表的公共节点 * * 两个链表长度分别为L1+C、L2+C, C为公共部分的长度,第一个人走了L1+C步后, * 回到第二个人起点走L2步;第2个人走了L2+C步后,回到第一个人起点走L1步。 * 当两个人走的步数都为L1+L2+C时这两个家伙就相爱了。 * * 时间复杂度:O(L1+L2+C) * 空间复杂度:O(1) */ public class Solution_1 { public ListNode findFirstCommonNode(ListNode pHead1, ListNode pHead2) { ...
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/Solution83.java
data_struct_study/src/LinkedList_problem/Solution83.java
package LinkedList_problem; /** * 删除链表中重复的节点 */ public class Solution83 { public ListNode deleteDuplicates(ListNode head) { // 1、如果当前节点为null或下一个节点为null时直接返回 if (head == null || head.next == null) { return head; } // 2、递归删除重复节点:如果当前节点与下一个节点值相等,则直接链接下一个节点 head....
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/Solution92.java
data_struct_study/src/LinkedList_problem/Solution92.java
package LinkedList_problem; /** * (1、m 和 n 超过链表范围怎么办?2、m > n 怎么办?) */ public class Solution92 { }
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/Solution19.java
data_struct_study/src/LinkedList_problem/Solution19.java
package LinkedList_problem; /** * 19: * 1、n从0计还是从1计。 * 2、n不合法,负数或者大于链表长度如何处理(保证n合法)。 * * O(n) * O(1) */ public class Solution19 { // 1、先遍历一遍计算链表长度;再遍历一遍得到待删除节点的前一个节点并删除待删除节点 public ListNode removeNthFromEnd(ListNode head, int n) { // 1、使用虚拟头结点 ListNode dummyHead = new ListNo...
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/Solution23.java
data_struct_study/src/LinkedList_problem/Solution23.java
package LinkedList_problem; import java.util.PriorityQueue; /** * 题目描述:给你一个链表数组,每个链表都已经按升序排列。 * 请你将所有链表合并到一个升序链表中,返回合并后的链表。 */ public class Solution23 { // 1、优先队列:用容量为K的最小堆优先队列,把链表的头结点都放进去,然后出队当前 // 优先队列中最小的,挂上链表,然后让 出队的那个节点指向的下一个节点 入队, // 如此反复,再出队当前优先队列中最小的,直到优先队列为空。 // 时间复杂度:O(n*log(k)),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/LinkedList_problem/Solution61.java
data_struct_study/src/LinkedList_problem/Solution61.java
package LinkedList_problem; public class Solution61 { }
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/Solution25.java
data_struct_study/src/LinkedList_problem/Solution25.java
package LinkedList_problem; /** * K 个一组翻转链表:不仅仅是穿针引线 * * 题目描述:给你一个链表,每 k 个节点一组进行翻转,请你返回翻转后的链表。 * k 是一个正整数,它的值小于或等于链表的长度。 * 如果节点总数不是 k 的整数倍,那么请将最后剩余的节点保持原有顺序 * * 1、链表分为已翻转部分+待翻转部分+未翻转部分 * 2、每次翻转前,通过 k 次循环来确定翻转链表的范围 * 3、需记录翻转链表前驱和后继,方便翻转完成后把已翻转部分和未翻转部分连接起来 * 4、初始需要两个变量 pre 和 end,pre 代表待翻转链表的前驱,end 代表待翻转链表的末尾 ...
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/Solution234.java
data_struct_study/src/LinkedList_problem/Solution234.java
package LinkedList_problem; /** * (1、遍历存到数组、判断数组。2、双指针) * 回文链表: 快慢指针(整除器),把剩下的一半变成逆序,再进行比较。注意奇偶情况讨论。 */ class Solution234 { public boolean isPalindrome(ListNode head) { if(head==null) return true; ListNode prev=null; ListNode slow=head, fast=head; while(fast!=null&&fast.next!=nu...
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/Solution206_2.java
data_struct_study/src/LinkedList_problem/Solution206_2.java
package LinkedList_problem; /** * 2、pre、cur、next + 递归 * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution206_2 { // Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } // 2、pre、cur、next + 递归...
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/Solution21.java
data_struct_study/src/LinkedList_problem/Solution21.java
package LinkedList_problem; /** * 合并两个有序链表为一个有序链表:设立链表的虚拟头结点 */ public class Solution21 { // 时间复杂度:O(n+m),函数 mergeTwoList 至多只会递归调用每个节点一次。 // 因此,时间复杂度取决于合并后的链表长度。 // 空间复杂度:O(n+m),递归调用 mergeTwoLists 函数时需要消耗栈空间,栈空间的大小 // 取决于递归调用的深度。结束递归调用时 mergeTwoLists 函数最多调用 n+m 次。 public ListNode mergeTwoLists(...
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/Solution206.java
data_struct_study/src/LinkedList_problem/Solution206.java
package LinkedList_problem; /** * 1、pre、cur、next + 循环: * * 在遍历列表时,将当前节点的 next 指针改为指向前一个元素。 * 由于节点没有引用其上一个节点,因此必须事先存储其前一个元素。在更改引用之前,还 * 需要另一个指针来存储下一个节点。不要忘记在最后返回新的头引用! * * 时间复杂度:O(n) * 空间复杂度:O(1) */ public class Solution206 { // Definition for singly-linked list. public class ListNode { int v...
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/Solution86.java
data_struct_study/src/LinkedList_problem/Solution86.java
package LinkedList_problem; public class Solution86 { }
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/Solution445.java
data_struct_study/src/LinkedList_problem/Solution445.java
package LinkedList_problem; import java.util.Stack; /** * 题目描述:给你两个 非空 链表来代表两个非负整数。数字最高位位于链表开始位置。 * 它们的每个节点只存储一位数字。将这两数相加会返回一个新的链表。 * 你可以假设除了数字 0 之外,这两个数字都不会以零开头。 * * 进阶:如果输入链表不能修改该如何处理?换句话说,你不能对列表中的节点进行翻转。 * * 示例: * 输入:(7 -> 2 -> 4 -> 3) + (5 -> 6 -> 4) * 输出:7 -> 8 -> 0 -> 7 * * 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/LinkedList_problem/Solution19_2.java
data_struct_study/src/LinkedList_problem/Solution19_2.java
package LinkedList_problem; /** * 19: * 1、n从0计还是从1计。 * 2、n不合法,负数或者大于链表长度如何处理(保证n合法)。 * * O(n) * O(1) */ public class Solution19_2 { // 2、双指针:设立两个指针 p、q,他们的距离为n,当 q 遍历到 null 时,p.next 即为 delNode public ListNode removeNthFromEnd(ListNode head, int n) { // 1、设立虚拟头结点,便于后续循环的计算 Lis...
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/Solution203.java
data_struct_study/src/LinkedList_problem/Solution203.java
package LinkedList_problem; /** * 使用虚拟头结点 * O(n) * O(1) */ public class Solution203 { // Definition for singly-linked list. public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ListNode removeElements(ListNode head, in...
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/Solution147.java
data_struct_study/src/LinkedList_problem/Solution147.java
package LinkedList_problem; public class Solution147 { }
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_3.java
data_struct_study/src/LinkedList_problem/Solution_3.java
package LinkedList_problem; /** * 题目描述:输入一个链表,输出该链表中倒数第k个节点。为了符合大多数人的习惯, * 本题从1开始计数,即链表的尾节点是倒数第1个节点。例如,一个链表有6个节点, * 从头节点开始,它们的值依次是1、2、3、4、5、6。 * 这个链表的倒数第3个节点是值为4的节点。 * * 设链表的长度为 N。设置两个指针 P1 和 P2,先让 P1 移动 K 个节点, * 则还有 N - K 个节点可以移动。此时让 P1 和 P2 同时移动, * 可以知道当 P1 移动到链表结尾时,P2 移动到第 N - K 个节点处, * 该位置就是倒数第 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/LinkedList_problem/Main.java
data_struct_study/src/LinkedList_problem/Main.java
package LinkedList_problem; /** * 链表,在节点间穿针引线 * * JsonChao的链表核心题库:22题 */ public class Main { }
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/Solution82.java
data_struct_study/src/LinkedList_problem/Solution82.java
package LinkedList_problem; /** * 设立链表的虚拟头结点 */ public class Solution82 { }
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/ListNode.java
data_struct_study/src/LinkedList_problem/ListNode.java
package LinkedList_problem; // Definition for singly-linked list. // 在Java版本中,我们将LinkedList相关的测试辅助函数写在ListNode里 public class ListNode { public int val; public ListNode next = null; public ListNode(int x) { val = x; } // 根据n个元素的数组arr创建一个链表 // 使用arr为参数,创建另外一个ListNode的构造函数 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/LinkedList_problem/Solution_2.java
data_struct_study/src/LinkedList_problem/Solution_2.java
package LinkedList_problem; /** * 单链表的选择排序: * * 时间复杂度:O(n^2) * 空间复杂度:O(1) */ public class Solution_2 { // 根据选择排序的思想寻找最小的元素,并利用头插法插入到节点 public ListNode sortInList (ListNode head) { // 1、创建一个虚拟头结点并将它指向真正的头结点,再赋值给已排序的链表 ListNode dummyHead = new ListNode(Integer.MAX_VALUE); dummyHead...
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/Student.java
data_struct_study/src/array/Student.java
package array; public class Student { private String name; private int score; public Student(String name, int score) { this.name = name; this.score = score; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ...
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/Array.java
data_struct_study/src/array/Array.java
package array; /** * 数组最大的优点:快速查询 * 数组最好应用于"索引有语义"的情况(但并非所有有语义的索引都适用于数组,例如身份证号码) * 我们需要额外处理索引有语义的情况 * 数组的容量:capacity,数组的大小:size,初始为0 * * 1、实现基本功能:增删改查、各种判断方法等等 * 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/array/Main.java
data_struct_study/src/array/Main.java
package array; public class Main { public static void main(String[] args) { Array<Integer> array = new Array<>(10); for (int i = 0; i < 10; i++) { array.addLast(i); } System.out.println(array); array.addLast(66); System.out.println(array); 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/other_problem/Solution_1.java
data_struct_study/src/other_problem/Solution_1.java
package other_problem; /** * 题目描述:将给出的32位整数x翻转。 * 例1:x=123,返回321 * 例2:x=-123,返回-321 * 你有注意到翻转后的整数可能溢出吗?因为给出的是32位整数,则其数值范围为[−2^{31}, 2^{31} − 1]。 * 翻转可能会导致溢出,如果反转后的结果会溢出就返回0。 * * 关键点是如何判断溢出。 * 推荐解答用的是用long类型存储结果,如果结果大于0x7fffffff或者小于0x80000000就溢出 * 我的解法是每次计算新的结果时,再用逆运算判断与上一次循环的结果是否相同,不同就溢出 */ public class Sol...
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/other_problem/Solution146.java
data_struct_study/src/other_problem/Solution146.java
package other_problem; import java.util.LinkedHashMap; /** * LRU Cache 146: * * 运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制 。 * 实现 LRUCache 类: * LRUCache(int capacity) 以正整数作为容量 capacity 初始化 LRU 缓存 * int get(int key) 如果关键字 key 存在于缓存中,则返回关键字的值,否则返回 -1 。 * void put(int key, int 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/other_problem/Solution393.java
data_struct_study/src/other_problem/Solution393.java
package other_problem; public class Solution393 { }
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/other_problem/Solution69.java
data_struct_study/src/other_problem/Solution69.java
package other_problem; public class Solution69 { public int mySqrt(int x) { if (x <= 1) { return x; } int l = 0, h = x; while (l <= h) { int mid = l + (h - l) / 2; int sqrt = x / mid; if (mid == sqrt) { return mid; ...
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/other_problem/Solution169.java
data_struct_study/src/other_problem/Solution169.java
package other_problem; import java.util.Arrays; public class Solution169 { public int majorityElement(int[] nums) { Arrays.sort(nums); return nums[nums.length / 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/other_problem/Solution169_2.java
data_struct_study/src/other_problem/Solution169_2.java
package other_problem; public class Solution169_2 { // 多数元素:我将这种算法称为 【抱对自杀】,每当一个众数碰到一个非众数就会抱住, // 然后双双自杀。如果没有遇到足够的非众数,众数们就会等人到齐了再抱对自杀。 // 最后留下来的当然是众数。 public int majorityElement(int[] nums) { int cnt = 0, majority = nums[0]; for (int num:nums) { majority = (cnt == 0) ? num...
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/other_problem/Solution176.java
data_struct_study/src/other_problem/Solution176.java
package other_problem; public class Solution176 { }
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/other_problem/Solution432.java
data_struct_study/src/other_problem/Solution432.java
package other_problem; public class Solution432 { }
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/other_problem/Solution231_2.java
data_struct_study/src/other_problem/Solution231_2.java
package other_problem; /** * 利用 1000 & 0111 == 0 */ public class Solution231_2 { public boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 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/other_problem/Solution136.java
data_struct_study/src/other_problem/Solution136.java
package other_problem; /** * 两个相同的数异或的结果为 0,对所有数进行异或操作,最后的结果就是单独出现的那个数。 */ public class Solution136 { public int singleNumber(int[] nums) { int res = 0; for (int num:nums) { res = res ^ num; } return res; } }
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/other_problem/Solution292.java
data_struct_study/src/other_problem/Solution292.java
package other_problem; public class Solution292 { }
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/other_problem/Main.java
data_struct_study/src/other_problem/Main.java
package other_problem; /** * Bloom Filter 布隆过滤器: * 1、一个很长的二进制向量和一个映射函数。 * 2、用于检索一个元素是否在一个集合中。 * 3、优点是空间和查询时间效率越超一般算法,缺点是有一定的误识别率(仅当存在时)和删除困难, * 所以仅仅是一个预先处理模块。 * * 位运算操作: * 1、X & 1 == 1 OR == 0 判断奇偶(X % 2 == 1) * 2、X = X & (X-1) => 清零最低位的1 * 3、X & -X => 得到最低位的1。 * 0s ...
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/other_problem/Solution9.java
data_struct_study/src/other_problem/Solution9.java
package other_problem; /** * 要求不能使用额外空间,也就不能将整数转换为字符串进行判断。 * * 将整数分成左右两部分,右边那部分需要转置,然后判断这两部分是否相等。 */ public class Solution9 { public boolean isPalindrome(int x) { if (x == 0) { return true; } if (x < 0 || x % 10 == 0) { return false; } int right...
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/other_problem/Solution7.java
data_struct_study/src/other_problem/Solution7.java
package other_problem; public class Solution7 { }
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/other_problem/Solution_2.java
data_struct_study/src/other_problem/Solution_2.java
package other_problem; import java.util.LinkedList; import java.util.Queue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; /** * 生产者消费者 */ public class Solution_2 { // 1、定义一个Message类 public class Message { ...
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/other_problem/Solution231.java
data_struct_study/src/other_problem/Solution231.java
package other_problem; /** * 二进制表示只有一个 1 存在。 */ public class Solution231 { public boolean isPowerOfTwo(int n) { return n > 0 && Integer.bitCount(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/map/Map.java
data_struct_study/src/map/Map.java
package map; public interface Map<K, V> { void add(K key, V value); V remove(K key); boolean contains(K key); V get(K key); void set(K key, V newValue); int getSize(); boolean isEmpty(); }
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/map/Solution1.java
data_struct_study/src/map/Solution1.java
package map; import java.util.ArrayList; import java.util.TreeMap; /** * Leetcode 350. Intersection of Two Arrays II * https://leetcode.com/problems/intersection-of-two-arrays-ii/description/ */ class Solution1 { public int[] intersect(int[] nums1, int[] nums2) { TreeMap<Integer, Integer> map = 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/map/LinkedListMap.java
data_struct_study/src/map/LinkedListMap.java
package map; import set.FileOperation; import java.util.ArrayList; public class LinkedListMap<K, V> implements Map<K, V> { private class Node { K key; V value; Node next; public Node(K key, V value, Node next) { this.key = key; this.value = 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/map/BSTMap.java
data_struct_study/src/map/BSTMap.java
package map; import set.FileOperation; import java.util.ArrayList; /** * 映射 Map * 1)、存储 Key:value 数据对的数据结构。 * 2)、根据 Key,寻找 Value。 * * 非常容易使用链表或者二分搜索树来实现。 * LinkedListMap BSTMap 平均 最差 * add、remove、set、get、contains O(n) O(h) O(logn) O(n) */ public cl...
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/recursion/Solution2.java
data_struct_study/src/recursion/Solution2.java
package recursion; /** * 不使用虚拟头结点 */ public class Solution2 { public ListNode removeElements(ListNode head, int val) { while (head != null && head.val == val) { // ListNode delNode = head; // head = head.next; // delNode = null; // 在 LeetCode不需要考虑用于内存释放的第一、三...
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/recursion/Sum.java
data_struct_study/src/recursion/Sum.java
package recursion; public class Sum { public static int sum(int[] arr){ return sum(arr, 0); } // 计算arr[l...n)这个区间内所有数字的和 private static int sum(int[] arr, int l){ if(l == arr.length) return 0; return arr[l] + sum(arr, l + 1); } public static void main(Stri...
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/recursion/Solution5.java
data_struct_study/src/recursion/Solution5.java
package recursion; /** * 理解递归调用过程: * * 1 -> 2 -> 6 -> 3 -> 4 -> 5 -> 6 -> NULL * Call: remove 6 in 1 -> 2 -> 6 -> 3 -> 4 -> 5 -> 6 -> NULL * --Call: remove 6 in 2 -> 6 -> 3 -> 4 -> 5 -> 6 -> NULL * ----Call: remove 6 in 6 -> 3 -> 4 -> 5 -> 6 -> NULL * ------Call: remove 6 in 3 -> 4 -> 5 -> 6 -> 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/recursion/Solution4.java
data_struct_study/src/recursion/Solution4.java
package recursion; public class Solution4 { public ListNode removeElements(ListNode head, int val) { if (head == null) { return null; } head.next = removeElements(head.next, val); return head.val == val ? head.next : head; } }
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/recursion/Solution.java
data_struct_study/src/recursion/Solution.java
package recursion; /** * Leetcode 203: Remove Linked List Elements * 删除多个节点时使用 while 循环。 * 1、Solution:注意内存释放 + 不使用虚拟头结点。 * 2、Solution2:不使用虚拟头结点。 * 3、Solution3:使用虚拟头结点。 */ class Solution { public ListNode removeElements(ListNode head, int val) { // 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/recursion/Solution3.java
data_struct_study/src/recursion/Solution3.java
package recursion; /** * 使用虚拟头结点 */ public class Solution3 { public ListNode removeElements(ListNode head, int val) { // 给真实的头结点前面添加一个虚拟的头结点 ListNode dummyHead = new ListNode(-1); dummyHead.next = head; ListNode pre = dummyHead; while (pre.next != null) { if...
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/recursion/Main.java
data_struct_study/src/recursion/Main.java
package recursion; /** * 递归:本质就是将原来的问题转换为更小的问题。 * * 1)、注意递归函数的宏观语义。 * 2)、递归函数就是一个普通的函数,仅完成一个功能而已。 * * 递归算法通常分为两步: * * 1)、求解基本问题。 * 2)、把原问题转化为更小的问题。 * * 递归调用是有代价的:函数调用 + 系统栈空间 * * 其它常见的链表类型: * 1)、双向链表,每一个 ListNode 同时具有 pre、next 指针 * 2)、双向循环链表:能够更进一步地封装很多便利的操作,Java 中的 LinkedList 的本质就是双向循环链表。 * 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/recursion/ListNode.java
data_struct_study/src/recursion/ListNode.java
package recursion; /** * Definition for singly-linked list. * */ public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } ListNode(int[] arr) { if (arr == null || arr.length == 0) { throw new IllegalArgumentException("ListNode is empty!"); ...
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_problem/Solution127.java
data_struct_study/src/queue_problem/Solution127.java
package queue_problem; public class Solution127 { }
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_problem/Solution23.java
data_struct_study/src/queue_problem/Solution23.java
package queue_problem; public class Solution23 { }
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_problem/Solution102.java
data_struct_study/src/queue_problem/Solution102.java
package queue_problem; import com.sun.tools.javac.util.Pair; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; /** * 树:层序遍历。102、107、103、199 * O(n) * O(n) * 二叉树的层次遍历:层次遍历和广度优先遍历其实是很像的, * 在循环中使用队列就好。唯一的不同是每一层单独一个list, * 因此我们就需要想想办法让每层分隔开,我使用的办法就是 * 每次塞进去一个root作为分隔。 */ public class...
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_problem/Solution279.java
data_struct_study/src/queue_problem/Solution279.java
package queue_problem; import LinkedList.LinkedList; import com.sun.tools.javac.util.Pair; /** * 图:无权图的最短路径。279 * 1、建模成图论问题:从n到0,每个数字表示一个节点, * 如果两个数字x到y相差一个完全平方数,则连接一条边。 * 我们得到了一个无权图。原问题转换为,求这个无权图中 * 从n到0的最短路径。 * * 暴力求解 * O(2^n) * O(2^n) */ public class Solution279 { public int num...
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_problem/Solution199.java
data_struct_study/src/queue_problem/Solution199.java
package queue_problem; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; /** * 题目描述:给定一棵二叉树,想象自己站在它的右侧,按照从顶部到底部的顺序,返回从右侧所能看到的节点值。 * * 一、BFS * 思路: 利用 BFS 进行层次遍历,记录下每层的最后一个元素。 * 时间复杂度: O(N),每个节点都入队出队了 1 次。 * 空间复杂度: O(N),使用了额外的队列空间。 * * 二、DFS (时间100%) * 思路: ...
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_problem/Solution107.java
data_struct_study/src/queue_problem/Solution107.java
package queue_problem; public class Solution107 { }
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_problem/Solution126.java
data_struct_study/src/queue_problem/Solution126.java
package queue_problem; /** * 优先队列(底层实现:堆) * 1、C++:priority_queue 底层默认实现是最大堆。 * 2、C++:priority_queue<int, vector<int>, greater<int>> 底层是最小堆。 */ public class Solution126 { }
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_problem/Solution103.java
data_struct_study/src/queue_problem/Solution103.java
package queue_problem; /** * 二叉树的之字形层序遍历 */ public class Solution103 { }
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_problem/Main.java
data_struct_study/src/queue_problem/Main.java
package queue_problem; /** * 队列的基本应用 - 广度优先遍历 * * JsonChao的队列核心题库:9题 */ public class Main { }
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_problem/Solution347.java
data_struct_study/src/queue_problem/Solution347.java
package queue_problem; import com.sun.tools.javac.util.Pair; import java.util.*; /** * 347: * 1、最简单的思路:扫描一遍统计概率,排序找到前k个出现频率最高的元素。时间复杂度:O(nlogn) * 2、使用优先队列不停地维护我们能找到的前k个出现频率最高的元素。时间复杂度:O(nlogk) */ public class Solution347 { private class MinComparator implements Comparator<Pair<Integer, Integer>> ...
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_problem/Solution279_2.java
data_struct_study/src/queue_problem/Solution279_2.java
package queue_problem; import LinkedList.LinkedList; import com.sun.tools.javac.util.Pair; /** * 使用 visited 数组,记录每一个入队元素 * O(n) * O(n) */ public class Solution279_2 { public int numSquares(int n) { if (n == 0) { return 0; } LinkedList<Pair<Integer, Integer>> queue = 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/LinkedList/LinkedListStack.java
data_struct_study/src/LinkedList/LinkedListStack.java
package LinkedList; import stack.Stack; public class LinkedListStack<E> implements Stack<E> { private LinkedList<E> list = new LinkedList<E>(); @Override public void push(E e) { list.addFirst(e); } @Override public E pop() { return list.removeFirst(); } @Override ...
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/LinkedListQueue.java
data_struct_study/src/LinkedList/LinkedListQueue.java
package LinkedList; import queue.LoopQueue; import queue.Queue; public class LinkedListQueue<E> implements Queue<E> { /** * Node 应该被设置成私有的,用户对此是无感知的。 */ private class Node { public E e; public Node next; public Node(E e, Node next) { this.e = e; this...
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/Main.java
data_struct_study/src/LinkedList/Main.java
package LinkedList; public class Main { public static void main(String[] args) { LinkedList<Integer> list = new LinkedList<Integer>(); for (int i = 0; i < 5; i++) { list.addFirst(i); System.out.println(list); } list.add(3, 99); System.out.println(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/LinkedList/LinkedList.java
data_struct_study/src/LinkedList/LinkedList.java
package LinkedList; /** * 为什么链表很重要? * 不同于 动态数组、栈、队列的实现:其底层是依托静态数组,靠 resize 解决固定容量问题, * 链表是真正的动态数据结构,也是最简单的动态数据结构。 * 能够帮助我们更深入地理解引用(指针)与递归。 * 优势:真正的动态,不需要处理固定容量的问题。 * 逆势:不同于数组其底层的数据是连续分布的,链表底层的数据分布是随机的, * 紧靠next(pre)指针连接,因此链表相对于数组丧失了随机访问的能力。 * * 数组和链表的区别? * 数组最好被应用于索引有语义的情况...
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_problem/Solution100.java
data_struct_study/src/binary_search_tree_problem/Solution100.java
package binary_search_tree_problem; public class Solution100 { }
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_problem/Solution124.java
data_struct_study/src/binary_search_tree_problem/Solution124.java
package binary_search_tree_problem; public class Solution124 { }
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_problem/Solution110.java
data_struct_study/src/binary_search_tree_problem/Solution110.java
package binary_search_tree_problem; public class Solution110 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } private boolean result = true; public boolean 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_problem/Solution104.java
data_struct_study/src/binary_search_tree_problem/Solution104.java
package binary_search_tree_problem; /** * 二叉树的最大深度 * 时间复杂度:O(n) * 空间复杂度:O(h) */ public class Solution104 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } pub...
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_problem/Solution113.java
data_struct_study/src/binary_search_tree_problem/Solution113.java
package binary_search_tree_problem; /** * 定义递归问题 */ public class Solution113 { }
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_problem/Solution198_8.java
data_struct_study/src/binary_search_tree_problem/Solution198_8.java
package binary_search_tree_problem; /** * DP:改变状态定义,优化转移方程 * O(n) * O(n) */ public class Solution198_8 { public int rob(int[] nums) { int n = nums.length; if (n == 0) { return 0; } // 考虑抢劫 [0..n) 房子得到的最大价值 int[] memo = new int[n]; memo[0] = nums[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/binary_search_tree_problem/Solution111.java
data_struct_study/src/binary_search_tree_problem/Solution111.java
package binary_search_tree_problem; public class Solution111 { public static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public int minDepth(TreeNode root) { if (root == null) { return 0; } in...
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_problem/Solution437.java
data_struct_study/src/binary_search_tree_problem/Solution437.java
package binary_search_tree_problem; /** * 更复杂的递归逻辑 * 1、node 在路径的情况 && 在 node 的左右子树中去查找它们的和是否为 sum。 * 2、node 在路径的情况需要处理为负数的情况,并且不一定需要计算到叶子节点。 * O(n) * O(h) */ public class Solution437 { public static class TreeNode { int val; TreeNode left; TreeNode right; 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/binary_search_tree_problem/Solution_1.java
data_struct_study/src/binary_search_tree_problem/Solution_1.java
package binary_search_tree_problem; /** * 二叉树根节点到所有叶子节点的路径之和: * 先序遍历的思想(根左右)+数字求和(每一层都比上层和*10+当前根节点的值) * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution_1 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(in...
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_problem/Solution230.java
data_struct_study/src/binary_search_tree_problem/Solution230.java
package binary_search_tree_problem; public class Solution230 { public static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } private int cnt = 0; private int val; public int kthSmallest(TreeNode root, int k) { inOrde...
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_problem/Solution222.java
data_struct_study/src/binary_search_tree_problem/Solution222.java
package binary_search_tree_problem; public class Solution222 { }
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_problem/Solution101.java
data_struct_study/src/binary_search_tree_problem/Solution101.java
package binary_search_tree_problem; public class Solution101 { public static class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public boolean isSymmetric(TreeNode root) { if (root == null) { 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/binary_search_tree_problem/Solution450.java
data_struct_study/src/binary_search_tree_problem/Solution450.java
package binary_search_tree_problem; /** * 1、若删除的节点不存在? * 2、是否可能有多个需要删除的节点。 * 3、删除的节点是否需要返回? */ public class Solution450 { }
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_problem/Solution235.java
data_struct_study/src/binary_search_tree_problem/Solution235.java
package binary_search_tree_problem; /** * 题目描述:给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先。 * 百度百科中最近公共祖先的定义为:“对于有根树 T 的两个结点 p、q, * 最近公共祖先表示为一个结点 x,满足 x 是 p、q 的祖先且 x * 的深度尽可能大(一个节点也可以是它自己的祖先)。” * * 二叉搜索树的最近公共祖先 * 时间复杂度:O(lgn) * 空间复杂度:O(n) */ public class Solution235 { public class TreeNode { int 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/binary_search_tree_problem/Solution98.java
data_struct_study/src/binary_search_tree_problem/Solution98.java
package binary_search_tree_problem; /** * 验证二叉搜索树:【递归】,又用到了树的经典划分:树=根+左子树+右子树。注意 * 这里左子树和右子树是包含于原树的范围的; 避免 Integer. MIN_VALUE * 和 Integer.MAX_VALUE,否则一些特殊的测试用例就会挂掉--这也是我们 * 使用Integer 而不是int作为上下限变量的原因。 */ public class Solution98 { // Definition for a binary tree node. public class TreeNode { int v...
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_problem/Solution226.java
data_struct_study/src/binary_search_tree_problem/Solution226.java
package binary_search_tree_problem; /** * O(n) * O(h) */ public class Solution226 { public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public TreeNode invertTree(TreeNode root) { if (root == null) { return...
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_problem/Solution257.java
data_struct_study/src/binary_search_tree_problem/Solution257.java
package binary_search_tree_problem; import java.util.ArrayList; import java.util.List; /** * 定义递归问题 * O(n) * O(h) */ public class Solution257 { public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public List<String> binaryTre...
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_problem/Solution112.java
data_struct_study/src/binary_search_tree_problem/Solution112.java
package binary_search_tree_problem; /** * 注意递归的终止条件 */ public class Solution112 { public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public boolean hasPathSum(TreeNode root, int sum) { if (root == 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/binary_search_tree_problem/Solution108.java
data_struct_study/src/binary_search_tree_problem/Solution108.java
package binary_search_tree_problem; public class Solution108 { public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public TreeNode sortedArrayToBST(int[] nums) { return toBST(nums, 0, 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/binary_search_tree_problem/Main.java
data_struct_study/src/binary_search_tree_problem/Main.java
package binary_search_tree_problem; /** * 二叉树天然的递归结构,空也是一颗二叉树。 * * JsonChao的二叉树核心题库:20题 */ 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/binary_search_tree_problem/Solution236.java
data_struct_study/src/binary_search_tree_problem/Solution236.java
package binary_search_tree_problem; /** * 二叉树的最近公共祖先 * 时间复杂度:O(n) * 空间复杂度:O(n) */ public class Solution236 { public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } public TreeNode lowestCommonAncestor(TreeNo...
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_problem/Solution_2.java
data_struct_study/src/binary_search_tree_problem/Solution_2.java
package binary_search_tree_problem; import java.util.*; /** * 题目描述:请实现一个函数按照之字形打印二叉树,即第一行按照 * 从左到右的顺序打印,第二层按照从右至左的顺序打印, * 第三行按照从左到右的顺序打印,其他行以此类推。 */ public class Solution_2 { // Definition for a binary tree node. public class TreeNode { int val; TreeNode left; TreeNode right; ...
java
Apache-2.0
f1c886eabf744b69e72a0b0a64b348032b439037
2026-01-05T02:39:40.141219Z
false