forked from rbmonster/learning-note
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sanwu
authored and
sanwu
committed
Feb 26, 2023
1 parent
f735b4c
commit 0ac55a1
Showing
23 changed files
with
169 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ng/algorithm/basic/listNode/ListNode.java → ...ng/algorithm/basic/listnode/ListNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...lgorithm/basic/listNode/MergeTwoList.java → ...lgorithm/basic/listnode/MergeTwoList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...algorithm/basic/listNode/OddEvenList.java → ...algorithm/basic/listnode/OddEvenList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...gorithm/basic/listNode/RemoveElement.java → ...gorithm/basic/listnode/RemoveElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/algorithm/basic/listNode/SwapPairs.java → ...g/algorithm/basic/listnode/SwapPairs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...arning/algorithm/basic/listNode/Test.java → ...arning/algorithm/basic/listnode/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.listNode; | ||
package com.learning.algorithm.basic.listnode; | ||
|
||
/** | ||
* <pre> | ||
|
47 changes: 47 additions & 0 deletions
47
src/main/java/com/learning/algorithm/basic/listnode/doublepointer/FastSlowPointer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.learning.algorithm.basic.listnode.doublepointer; | ||
|
||
import com.learning.algorithm.basic.listnode.ListNode; | ||
|
||
public class FastSlowPointer { | ||
|
||
/** | ||
* 查找链表中点 | ||
* @param head | ||
* @return | ||
*/ | ||
public ListNode findMid(ListNode head) { | ||
if (head == null || head.next == null) { | ||
return head; | ||
} | ||
ListNode fast = head.next; | ||
ListNode slow = head; | ||
while(fast != null && fast.next !=null) { | ||
fast = fast.next.next; | ||
slow = slow.next; | ||
} | ||
return slow; | ||
} | ||
|
||
/** | ||
* 查找倒数第N个节点 | ||
* @param head | ||
* @param n | ||
* @return | ||
*/ | ||
public ListNode findLastN(ListNode head, int n) { | ||
ListNode fast = head; | ||
while(fast != null && n >0) { | ||
fast = fast.next; | ||
n--; | ||
} | ||
if (fast == null) { | ||
return null; | ||
} | ||
ListNode slow = head; | ||
while(fast !=null) { | ||
slow = slow.next; | ||
fast = fast.next; | ||
} | ||
return slow; | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
.../basic/listNode/doublePoint/HasCycle.java → ...asic/listnode/doublepointer/HasCycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...istNode/doublePoint/IntersectionNode.java → ...tnode/doublepointer/IntersectionNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
.../algorithm/basic/treeNode/BstIsValid.java → .../algorithm/basic/treenode/BstIsValid.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...g/algorithm/basic/treeNode/BuildTree.java → ...g/algorithm/basic/treenode/BuildTree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gorithm/basic/treeNode/DeleteBSTNode.java → ...gorithm/basic/treenode/DeleteBSTNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.treeNode; | ||
package com.learning.algorithm.basic.treenode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...ing/algorithm/basic/treeNode/InOrder.java → ...ing/algorithm/basic/treenode/InOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../algorithm/basic/treeNode/LevelOrder.java → .../algorithm/basic/treenode/LevelOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g/algorithm/basic/treeNode/PostOrder.java → ...g/algorithm/basic/treenode/PostOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ng/algorithm/basic/treeNode/PreOrder.java → ...ng/algorithm/basic/treenode/PreOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...orithm/basic/treeNode/SortArrayToBST.java → ...orithm/basic/treenode/SortArrayToBST.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.treeNode; | ||
package com.learning.algorithm.basic.treenode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...lgorithm/basic/treeNode/TreeMaxDepth.java → ...lgorithm/basic/treenode/TreeMaxDepth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.treeNode; | ||
package com.learning.algorithm.basic.treenode; | ||
|
||
/** | ||
* <pre> | ||
|
2 changes: 1 addition & 1 deletion
2
...lgorithm/basic/treeNode/TreeMinDepth.java → ...lgorithm/basic/treenode/TreeMinDepth.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ng/algorithm/basic/treeNode/TreeNode.java → ...ng/algorithm/basic/treenode/TreeNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.learning.algorithm.basic.treeNode; | ||
package com.learning.algorithm.basic.treenode; | ||
|
||
/** | ||
* <pre> | ||
|