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
/* | |
Copy List with Random Pointer - LeetCode: https://leetcode.com/problems/copy-list-with-random-pointer/ | |
*/ | |
// This code passes all Leetcode test cases as of Oct. 3rd 2019 | |
class LinearSpaceApproach { | |
public Node copyRandomList(Node head) { | |
if (head == null) { | |
return null; | |
} |
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
/* | |
Merge Two Sorted Lists - LeetCode: https://leetcode.com/problems/merge-two-sorted-lists | |
Authorship: ALL credit for the iterative code in this file goes to the | |
authors of the book "Elements of Programming Interviews" by Adnan Aziz, | |
Amit Prakash, and Tsung-Hsien Lee. | |
I have just adapted the solution to pass on Leetcode, added explanatory | |
comments, reformatted the code, & changed variable names for understanding. |
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
/* | |
Kth Largest Element in an Array - LeetCode: https://leetcode.com/problems/kth-largest-element-in-an-array/ | |
This optimal solution has the same fundamental reasoning that QuickSort uses. (the partitioning subroutine) | |
Check out that QuickSort video here: https://www.youtube.com/watch?v=uXBnyYuwPe8 | |
This code passes all Leetcode test cases as of April 18 2019 | |
Runtime: 1 ms, faster than 99.86% of Java online submissions for Kth Largest Element in an Array |
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
/* | |
Quicksort. Picking the pivot is 'pivotal' to the | |
algorithm's performance ;) | |
This version picks the last item in the partition space | |
as the pivot everytime, there are many other ways to choose | |
a pivot item. | |
The video to explain this code is here: https://www.youtube.com/watch?v=uXBnyYuwPe8 | |
*/ |
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
/* | |
Sort List - LeetCode: https://leetcode.com/problems/sort-list/ | |
This code passes all Leetcode test cases as of Sept. 28 2019 | |
*/ | |
// The split subroutine | |
public ListNode sortList(ListNode head) { | |
/* | |
Base case, an empty list or a single item list. That is a sorted list, | |
hence we just return the list (it is either empty or only has 1 item) |
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
/* | |
A min heap implementation | |
Array Form: [ 5, 7, 6, 10, 15, 17, 12 ] | |
Complete Binary Tree Form: | |
5 | |
/ \ | |
7 6 | |
/ \ / \ |
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
/* | |
Authorship: ALL credit for the code in this file goes to the authors of the | |
book "Elements of Programming Interviews" by Adnan Aziz, Amit Prakash, and | |
Tsung-Hsien Lee. | |
I have just adapted the solution to pass on Leetcode, added explanatory | |
comments, reformatted the code, & changed variable names for understanding. | |
Sudoku Solver - LeetCode: https://leetcode.com/problems/sudoku-solver/ |
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
/* | |
Authorship: ALL credit for the code in this file goes to the authors of the | |
book "Elements of Programming Interviews" by Adnan Aziz, Amit Prakash, and | |
Tsung-Hsien Lee. | |
I have just adapted the code to pass on Leetcode, added explanatory comments, | |
reformatted the code, & changed variable names for understanding. | |
Generate Parentheses - LeetCode: https://leetcode.com/problems/generate-parentheses |
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
/* | |
Serialize and Deserialize Binary Tree - LeetCode: | |
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/ | |
This code passes all Leetcode test cases as of April 26 2019 | |
Runtime: 12 ms, faster than 62.25% of Java online submissions for Serialize and Deserialize Binary Tree. | |
Memory Usage: 39.4 MB, less than 71.37% of Java online submissions for Serialize and Deserialize Binary Tree. | |
The video to explain this code is here: https://www.youtube.com/watch?v=suj1ro8TIVY | |
*/ |
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
/* | |
Binary Tree Level Order Traversal - LeetCode: | |
https://leetcode.com/problems/binary-tree-level-order-traversal/ | |
This code passes all Leetcode test cases as of Feb. 3 2019 | |
Runtime: 1 ms, faster than 82.85% of Java online submissions for Binary Tree Level Order Traversal. | |
Memory Usage: 26.5 MB, less than 64.46% of Java online submissions for Binary Tree Level Order Traversal. | |
The video to explain this code is here: https://www.youtube.com/watch?v=gcR28Hc2TNQ | |
*/ |