MCPcopy Create free account

hub / github.com/FreeTymeKiyan/LeetCode-Sol-Res / functions

Functions1,974 in github.com/FreeTymeKiyan/LeetCode-Sol-Res

MethoddeleteDuplicates
src/main/cpp/083_Remove_Duplicates_from_Sorted_List.cpp:25
MethoddeleteDuplicates
nested while loop, skip next node
src/main/java/com/freetymekiyan/algorithms/level/easy/RemoveDuplicatesFromSortedList.java:21
MethoddeleteNode
(ListNode node)
src/main/java/com/freetymekiyan/algorithms/level/easy/DeleteNodeInLinkedList.java:16
MethoddepthSum
Recursive. sum = all integer's sum at this depth + all depthSum of other lists.
src/main/java/com/freetymekiyan/algorithms/level/easy/NestedListWeightSum.java:28
MethoddepthSumInverse
DFS. Instead of level, pass the integer sum of this level to the next level. Recurrence Relation: sum = this level's integers' sum + all previous leve
src/main/java/com/freetymekiyan/algorithms/level/medium/NestedListWeightSum2.java:39
MethoddepthSumInverseB
DFS. Iterative. Add integer in list multiple times. Sum of current level is: sum of all integers in this level + sum of all integers in previous level
src/main/java/com/freetymekiyan/algorithms/level/medium/NestedListWeightSum2.java:80
Methoddequeue
()
src/main/java/com/freetymekiyan/datastructures/LinkedListQueue.java:26
Methoddeserialize
(String data)
src/main/java/com/freetymekiyan/algorithms/level/medium/SerializeAndDeserializeBst.java:59
MethoddetectCycle
Reset slow to head after cycle is detected Then move until slow and fast meets Each one step every time
src/main/java/com/freetymekiyan/algorithms/level/medium/LinkedListCycle2.java:22
Methoddfs
src/main/cpp/108_Convert_Sorted_Array_to_Binary_Search_Tree.cpp:28
Methoddfs
cur: {string} expression generated so far. pos: {int} current visiting position of num. cv: {long} cumulative value so far. pv: {long} previo
src/main/cpp/282_Expression_Add_Operators.cpp:31
Methoddfs
src/main/cpp/126_Word_Ladder_II.cpp:122
Methoddfs
src/main/cpp/126_Word_Ladder_II.cpp:252
Methoddfs
src/main/cpp/124_Binary_Tree_Maximum_Path_Sum.cpp:53
Methoddfs
(int[] num)
src/main/java/com/freetymekiyan/algorithms/level/medium/Permutations.java:21
Methoddfs
Topological Sort. DFS. Create a boolean array from visited state of each node. Create a stack to store the result. Then dfs each unvisited node. Final
src/main/java/com/freetymekiyan/algorithms/level/medium/CourseSchedule2.java:128
MethoddfsRecursive
DFS. Recursive. Base case: If out of the grid or is not land, return. Recurrence: If it is an island, set it to '0' as visited. Then recursively searc
src/main/java/com/freetymekiyan/algorithms/level/medium/NumberOfIslands.java:121
MethoddiameterOfBinaryTree
Recursive. Recurrence relation: Diameter is the # of edges of the longest path between 2 nodes. If two nodes are in the same tree, the diameter is the
src/main/java/com/freetymekiyan/algorithms/level/easy/DiameterOfBinaryTree.java:63
MethoddiameterOfBinaryTree2
Recursive. DFS. Get the diameter of each node then return the maximum. Diameter = depth(left subtree) + depth(right subtree). Maintain an 1-element ar
src/main/java/com/freetymekiyan/algorithms/level/easy/DiameterOfBinaryTree.java:32
MethoddiffWaysToCompute
Divide and Conquer. Divide the input into sub-strings according to the operator: left and right. Stop until there is no operator in the string, parse
src/main/java/com/freetymekiyan/algorithms/level/medium/DifferentWaysToAddParentheses.java:40
Methoddijkstra
(String startName)
src/main/java/com/freetymekiyan/algorithms/other/Dijkstra.java:39
Methoddivide
(int dividend, int divisor)
src/main/java/com/freetymekiyan/algorithms/level/medium/DivideTwoIntegers.java:33
MethodedgeCases
()
src/test/java/com/freetymekiyan/algorithms/level/hard/LongestSubstringWithAtMostTwoDistinctCharactersTest.java:24
Methodempty
()
src/main/java/com/freetymekiyan/algorithms/level/easy/ImplementingQueueWithStacks.java:60
Methodencode
Traverse the source string Append current char to result first Get count with a loop, note the edge case Append count of current char to result
src/main/java/com/freetymekiyan/algorithms/other/RunLengthEncoding.java:22
Methodencode
(String longUrl)
src/main/java/com/freetymekiyan/algorithms/level/medium/EncodeAndDecodeTinyURL.java:29
Methodencode
(List<String> strs)
src/main/java/com/freetymekiyan/algorithms/level/medium/EncodeAndDecodeStrings.java:52
Methodenqueue
(Item item)
src/main/java/com/freetymekiyan/datastructures/LinkedListQueue.java:13
MethodexampleCases
()
src/test/java/com/freetymekiyan/algorithms/level/hard/LongestSubstringWithAtMostTwoDistinctCharactersTest.java:9
Methodfind
(int value)
src/main/java/com/freetymekiyan/algorithms/level/easy/TwoSum3DataStructureDesign.java:40
MethodfindCelebrity
Pick the candidate first. If a candidate doesn't know someone, that guy cannot be candidate, candidate remains the same. If a candidate knows someone,
src/main/java/com/freetymekiyan/algorithms/level/medium/FindTheCelebrity.java:43
MethodfindDuplicate1
Floyd's loop detection Two pointers, O(n)
src/main/java/com/freetymekiyan/algorithms/level/hard/FindDupNum.java:20
MethodfindDuplicate2
Binary Search, O(nlogn) count: how many numbers are below the half value if count > mid, dup in lower range else dup in upper range
src/main/java/com/freetymekiyan/algorithms/level/hard/FindDupNum.java:42
MethodfindItinerary
(String[][] tickets)
src/main/java/com/freetymekiyan/algorithms/level/medium/ReconstructItinerary.java:41
MethodfindKthLargestB
QuickSelect Use partition algorithm in Quick Sort Compare partition index with k - 1 If index > k - 1, means upper bound can be index - 1 If index < k
src/main/java/com/freetymekiyan/algorithms/other/KthLargest.java:42
MethodfindLadders
src/main/cpp/126_Word_Ladder_II.cpp:274
MethodfindLca
If root is null, just return null If root's value matches with n1 or n2, return root If not, find lca recursively in both left and right subtrees If b
src/main/java/com/freetymekiyan/algorithms/other/LowestCommonAncestor.java:23
MethodfindLeaves
Tree, DFS(Backtracking). Make use of one property of tree node, its getHeight. Height is the number of edges from the node to the deepest leaf. So lea
src/main/java/com/freetymekiyan/algorithms/level/medium/FindLeavesOfBinaryTree.java:49
MethodfindMaxLength
Hash Table. Use an integer, count, to track the difference between # of 0s and # of 1s. Whenever the difference is the same, there are equal # of 0s a
src/main/java/com/freetymekiyan/algorithms/level/medium/ContiguousArray.java:37
MethodfindMaxLength2
Hash Table. Use map directly.
src/main/java/com/freetymekiyan/algorithms/level/medium/ContiguousArray.java:59
MethodfindMin
Binary Search. Compare nums[mid] with nums[hi]. When nums[mid] = nums[hi], we are not sure which side contains the min. So we just shrink the solution
src/main/java/com/freetymekiyan/algorithms/level/hard/FindMinimumInRotatedSortedArray2.java:28
MethodfindMin
(int[] nums)
src/main/java/com/freetymekiyan/algorithms/level/medium/FindMinimuminRotatedSortedArray.java:16
MethodfindNthDigit
(int n)
src/main/java/com/freetymekiyan/algorithms/level/easy/NthDigit.java:35
MethodfindNumberOfLIS2
Segment Tree. TBA.
src/main/java/com/freetymekiyan/algorithms/level/medium/NumberOfLongestIncreasingSubsequence.java:74
MethodfindOrder
(int numCourses, int[][] prerequisites)
src/main/java/com/freetymekiyan/algorithms/level/medium/CourseSchedule2.java:62
MethodfindOrder2
Topological Sort. Graph represented with map.
src/main/java/com/freetymekiyan/algorithms/level/medium/CourseSchedule2.java:173
MethodfindPartition
use backtracking to find partition maintain a stack of palindrome and keep checking if the sub-tree of the top node is palindrome
src/main/cpp/131_Palindrome_Partitioning.cpp:47
MethodfindPartition
use backtracking to find partition maintain a stack of palindrome and keep checking if the sub-tree of the top node is palindrome
src/main/cpp/131_Palindrome_Partitioning.cpp:88
MethodfindRepeatedDnaSequences
src/main/cpp/187_Repeated_DNA_Sequences.cpp:114
MethodfindRepeatedDnaSequences
To optimize space usage, map string to other key that won't collide Design a hash function according to observation A: 0x41, C: 0x43, G: 0x47, T: 0x54
src/main/java/com/freetymekiyan/algorithms/level/medium/RepeatedDNASeq.java:37
MethodfindRepeatedDnaSequences
Hash Table. Bit Manipulation. To optimize space usage, map string to other key that won't collide. Design a hash function according to observation. A:
src/main/java/com/freetymekiyan/algorithms/level/medium/RepeatedDNASequences.java:41
MethodfindRepeatedDnaSequencesB
HashSet with previous appeared results O(n) Space
src/main/java/com/freetymekiyan/algorithms/level/medium/RepeatedDNASeq.java:59
MethodfindRepeatedDnaSequencesB
Hash Table. O(n) Time & Space. HashSet with previous appeared results.
src/main/java/com/freetymekiyan/algorithms/level/medium/RepeatedDNASequences.java:65
MethodfindSubstring
https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems For most substring problem, we are given a
src/main/java/com/freetymekiyan/algorithms/level/hard/MinimumWindowSubstring.java:163
MethodfindSubstring
(String S, String[] L)
src/main/java/com/freetymekiyan/algorithms/level/hard/SubstringWithConcatenationOfAllWords.java:32
MethodfindTarget
Set. Traverse the tree and add traversed node values to a set. At every new node, check if target - current node's value exists in the set.
src/main/java/com/freetymekiyan/algorithms/level/medium/TwoSumIVBST.java:49
MethodfindTarget2
BST, In-Order Traversal, Two Pointers. In-order traversal generates values in ascending order. Then use two pointers to check the target.
src/main/java/com/freetymekiyan/algorithms/level/medium/TwoSumIVBST.java:66
MethodfindTargetSumWays
DFS. One number can either be + / -. Traverse all possibilities to the end of the array and get the sum. Compare the sum with S. If sum == s, count++.
src/main/java/com/freetymekiyan/algorithms/level/medium/TargetSum.java:43
MethodfindTargetSumWays2
DP, Bottom up. State: Number of ways that can reach a sum j at index i, dp[i][j]. Base case: Sum 0 has 1 way to reach, dp[0][0] = 1. Recurrence Relati
src/main/java/com/freetymekiyan/algorithms/level/medium/TargetSum.java:75
MethodfindTheDifference
(String s, String t)
src/main/java/com/freetymekiyan/algorithms/level/easy/FindTheDifference.java:32
MethodfindTheDifference2
(String s, String t)
src/main/java/com/freetymekiyan/algorithms/level/easy/FindTheDifference.java:42
MethodfindWords
Build a trie for the words When backtracking, move forward with the trie node Do pruning when the current char is not in the trie
src/main/java/com/freetymekiyan/algorithms/level/hard/WordSearch2.java:43
Methodfindpath
src/main/cpp/332_Reconstruct_Itinerary.cpp:46
MethodfirstBadVersion
Binary Search. Initial search range: n versions from 1 to n. Get the middle version m. If m is bad, then m+1 to n are all bad. The first bad version c
src/main/java/com/freetymekiyan/algorithms/level/easy/FirstBadVersion.java:31
MethodfirstBadVersion2
Binary Search. Pruning. If we know m is a bad version, we can check m - 1 right after that. If m - 1 is 1, which means that's the only available good
src/main/java/com/freetymekiyan/algorithms/level/easy/FirstBadVersion.java:52
Methodflatten
Iteration. For current node, if left subtree is not null: | Find the right most node of left subtree. | Connect it with root.right. | Set root.right t
src/main/java/com/freetymekiyan/algorithms/level/medium/FlattenBinaryTreeToLinkedList.java:46
MethodflattenB
Recursion. Suppose flatten already works. The result is flatten the left subtree, then the right subtree. Then set root.right to left subtree and conn
src/main/java/com/freetymekiyan/algorithms/level/medium/FlattenBinaryTreeToLinkedList.java:68
Methodfloor
(Key key)
src/main/java/com/freetymekiyan/datastructures/BST.java:46
Methodfollow
(int followerId, int followeeId)
src/main/java/com/freetymekiyan/algorithms/level/medium/DesignTwitter.java:79
MethodfourSum
Four pointers, O(n^3) time First pointer i starts from 1 to num.length - 4, 3 indices remain Second pointer j starts from i + 1 to num.length - 3, 2 i
src/main/java/com/freetymekiyan/algorithms/level/medium/FourSum.java:36
MethodfourSum
(int[] num, int target)
src/main/java/com/freetymekiyan/algorithms/level/medium/FourSumTreeMap.java:10
MethodgameOfLife
Bit-manipulation. Use 2 bit for each cell to represent both current and next states. 00, 01, 10, 11. Then scan the matrix again to generate result.
src/main/java/com/freetymekiyan/algorithms/level/medium/GameOfLife.java:36
Methodgenerate
Definition
src/main/java/com/freetymekiyan/algorithms/level/easy/PascalsTriangle.java:30
MethodgenerateExamples
()
src/test/java/com/freetymekiyan/algorithms/level/medium/CombinationSum4Test.java:9
MethodgenerateMatrixB
use startR, endR, startC, endC to mark the range update relative range whenever finish filling up a row or column
src/main/java/com/freetymekiyan/algorithms/level/medium/SpiralMatrix2.java:54
MethodgeneratePossibleNextMoves
(String s)
src/main/java/com/freetymekiyan/algorithms/level/easy/FlipGame.java:34
MethodgeneratePossibleNextMoves2
(String s)
src/main/java/com/freetymekiyan/algorithms/level/easy/FlipGame.java:41
MethodgenerateTrees
1..n is the in-order traversal for any BST with nodes 1 to n. if pick i-th node as root the left subtree will contain elements 1 to (i-1) and the righ
src/main/java/com/freetymekiyan/algorithms/level/medium/UniqueBinarySearchTrees2.java:33
MethodgetBlankInput
()
src/test/java/com/freetymekiyan/algorithms/level/easy/FirstUniqueCharacterInAStringTest.java:19
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/AddTwoDoublesTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/MedianOfNSortedArraysTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/BinaryTreeLongestPathTest.java:11
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/AlmostBalancedTreeTest.java:11
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/BinaryTreeToCircularDoublyLinkedListTest.java:11
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/FindSecondLargestTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/MinimumDistanceOfTwoSortedArraysTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/ValidParentheseStringTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/LCAOfDeepestLeavesTest.java:13
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/other/TotalNumberOfSecondsTest.java:11
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/WildcardMatchingTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/MinimumWindowSubstringTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/WordLadder2Test.java:12
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/TextJustificationTest.java:11
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/PalindromePairsTest.java:12
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/LongestConsecutiveSeqTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/MinimumWindowSubsequenceTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/hard/MedianOfTwoSortedArraysTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/medium/KthLargestElementInAnArrayTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/medium/NumberOfLongestIncreasingSubsequenceTest.java:9
MethodgetExamples
()
src/test/java/com/freetymekiyan/algorithms/level/medium/AccountsMergeTest.java:44
← previousnext →1,001–1,100 of 1,974, ranked by callers