剑指offer
Data Structures & Algorithms · 55 notes
- String Permutationshistorical
Generate all string permutations using recursive backtracking, deduplicate them, and sort them lexicographically.
- Jump Floorhistorical
Use the Fibonacci recurrence to calculate the number of ways a frog can climb the stairs.
- Jump Floor IIhistorical
Derive the number of ways to climb stairs when each jump may cover any number of steps using a recurrence and a pattern.
- Fibonacci Sequencehistorical
Record three implementations of the Fibonacci sequence: recursion, memoization, and dynamic programming.
- Number of 1 Bitshistorical
Count the number of 1 bits in a 32-bit binary representation by shifting through each bit.
- Integer Power of a Numberhistorical
Calculate a floating-point number raised to an integer power using repeated multiplication, including negative exponents.
- Number of Digit 1 Occurrenceshistorical
Enumerate integers and use modulo operations to count occurrences of digit 1 in decimal representations from 1 to n.
- First Non-Repeating Character in a Character Streamhistorical
Use a map to count character occurrences while preserving input order to find the first character that appears only once in a stream.
- Left Rotate Stringhistorical
Record two implementations of cyclic left rotation of a string: slicing and concatenation, and three reversals.
- Poker Straighthistorical
Sort five cards, treat jokers as 0, and use the gaps between non-zero cards to determine whether they can form a straight.
- Replace Spaceshistorical
Record two implementations for replacing spaces with %20: character-by-character concatenation and preallocated storage.
- Print Linked List from Tail to Headhistorical
Record recursive and stack-based methods for outputting a linked list from tail to head.
- Reverse Linked Listhistorical
Record stack-based and three-pointer implementations for reversing a singly linked list.
- Merge Two Sorted Linked Listshistorical
Record iterative and recursive implementations for merging two sorted linked lists.
- K-th Node from the End of a Linked Listhistorical
Record array, length-conversion, and fast-slow-pointer methods for finding the k-th node from the end.
- Copy Complex Linked Listhistorical
Record the method of copying a complex linked list by inserting copied nodes after the original nodes.
- Entry Node of a Loop in a Linked Listhistorical
Record set-based and fast/slow-pointer methods for finding the entry node of a linked-list cycle.
- First Common Node of Two Linked Listshistorical
Record a two-pointer method that uses the length difference to find the first common node of two linked lists.
- Delete Duplicate Nodes in a Linked Listhistorical
Record counting- and set-based methods for deleting all duplicate nodes from a sorted linked list.
- Postorder Traversal Sequence of a Binary Search Treehistorical
Record a recursive method for determining whether a sequence is the postorder traversal result of a binary search tree.
- Next Node in a Binary Treehistorical
Record methods for finding the inorder successor of a binary-tree node through a full inorder traversal or parent-pointer relationships.
- Binary Search Tree and Doubly Linked Listhistorical
Record inorder-traversal and recursive methods for converting a binary search tree into a sorted doubly linked list.
- Kth Node in a Binary Search Treehistorical
Record inorder-traversal methods for finding the kth smallest node in a binary search tree, plus reverse inorder traversal for the kth largest node.
- Depth of a Binary Treehistorical
Record a recursive method for computing binary-tree depth by taking the greater depth of the left and right subtrees.
- Print a Binary Tree from Top to Bottomhistorical
Record queue-based level-order traversal for printing binary-tree nodes from top to bottom.
- Symmetric Binary Treehistorical
Record a recursive method for determining whether a binary tree is symmetric by comparing mirrored positions in its left and right subtrees.
- Balanced Binary Treehistorical
Record a method for determining whether a binary tree is balanced by comparing subtree heights and recursively checking both subtrees.
- Mirror of a Binary Treehistorical
Record recursive, stack-based, and queue-based methods for generating the mirror of a binary tree by swapping left and right subtrees.
- Print a Binary Tree in Multiple Lineshistorical
Record a queue-based method that uses end-of-line pointers to print a binary tree level by level, one line per level.
- Print a Binary Tree in Zigzag Orderhistorical
Record a zigzag traversal method by reversing alternating rows after level-order traversal.
- Substructure of a Treehistorical
Record a preorder-recursive matching method for determining whether one binary tree is a substructure of another.
- Reconstruct Binary Treehistorical
Record the recursive method for reconstructing a binary tree from preorder and inorder traversal results.
- Paths in a Binary Tree With a Given Sumhistorical
Record the depth-first, preorder traversal, and backtracking method for finding binary-tree paths with a given sum.
- Serialize a Binary Treehistorical
Record methods for serializing and deserializing a binary tree using preorder traversal and a preorder-plus-inorder traversal combination.
- Convert a String to an Integerhistorical
Record character parsing and atoi implementations for converting a string to an integer.
- Reverse Word Orderhistorical
Record methods for reversing word order by splitting the string and by reversing twice.
- Stack with a min Functionhistorical
Record using an auxiliary minimum stack to retrieve the stack minimum in O(1) time.
- Stack Push and Pop Sequenceshistorical
Record methods that use an auxiliary stack to determine whether a given sequence is a valid pop sequence.
- Implement a Queue with Two Stackshistorical
Record how to implement queue Push, Pop, Peek, and Empty operations using two stacks.
- Search in a 2D Arrayhistorical
Mirror translation of the original Sword Offer note: Search in a 2D Array.
- Two Numbers with Sum Shistorical
Mirror translation of the original Sword Offer note: Two Numbers with Sum S.
- Continuous Positive Sequences with Sum Shistorical
Mirror translation of the original Sword Offer note: Continuous Positive Sequences with Sum S.
- Last Remaining Number in a Circlehistorical
Mirror translation of the original Sword Offer note: Last Remaining Number in a Circle.
- Arrange an Array into the Smallest Numberhistorical
Mirror translation of the original Sword Offer note: Arrange an Array into the Smallest Number.
- Count Occurrences in a Sorted Arrayhistorical
Mirror translation of the original Sword Offer note: Count Occurrences in a Sorted Array.
- Number Appearing More Than Half the Timehistorical
Mirror translation of the original Sword Offer note: Number Appearing More Than Half the Time.
- Numbers Appearing Only Oncehistorical
Mirror translation of the original Sword Offer note: Numbers Appearing Only Once.
- Inverse Pairs in an Arrayhistorical
Mirror translation of the original Sword Offer note: Inverse Pairs in an Array.
- Duplicate Number in an Arrayhistorical
Mirror translation of the original Sword Offer note: Duplicate Number in an Array.
- Minimum Number in a Rotated Arrayhistorical
Mirror translation of the original Sword Offer note: Minimum Number in a Rotated Array.
- Smallest K Numbershistorical
Mirror translation of the original Sword Offer note: Smallest K Numbers.
- Robot Movement Rangehistorical
Mirror translation of the original Sword Offer note: Robot Movement Range.
- Maximum in Sliding Windowshistorical
Mirror translation of the original Sword Offer note: Maximum in Sliding Windows.
- Reorder Array with Odd Numbers Before Even Numbershistorical
Mirror translation of the original Sword Offer note: Reorder Array with Odd Numbers Before Even Numbers.
- Maximum Sum of a Contiguous Subarrayhistorical
Mirror translation of the original Sword Offer note: Maximum Sum of a Contiguous Subarray.