Projective Geometry
Projection from 3D to 2D lost information
length
angles
scale (cannot be recovered)
Why?
Euclidean vs. Projective Geometry
Projective Geometry
Lost: Angles, distance, ratio of distances
Preserved: straightness
We study of geometric properties that are invariant wrt projective transformations in projective geometr...
Merge k Sorted Lists
23. Merge k Sorted Lists
Solutions - Divide and Conquer
Use a dummy Node(0) to represent the first Node.
When one of the lists has reached to the end, can directly append another list to the end.
def mergeKLists(self, lists):
"""
:type lists: List[ListNode]
:rtype: ListNode
"""
l = len(lists)
if l ...
Lowest Common Ancestor of a Binary Search Tree
235. Lowest Common Ancestor of a Binary Search Tree
Solutions
Use the definition of BST. The ancestor can only be updated when p and q are in the same subtree of the current node.
Kth Smallest Element in a BST
230. Kth Smallest Element in a BST
Solutions - In-order Traversal
A helper function to traverse the tree in order.
The function will be popped up from the stack, and thus its result is reversed.
count-- for each ‘root’ node.
When count == 0, we have found the result.
Subtree of Another Tree
572. Subtree of Another Tree
Solutions
Check tree with each node as root recursively.
Implement Trie (Prefix Tree)
208. Implement Trie (Prefix Tree)
Solutions
Store words in dictionary whose key is the first character of words, and value is a list of words.
startsWith() requires the first several characters to be known, we can use this information to narrow down the search space.
Similar to 211. Add and Search Word - Data structure design
Add and Search Word - Data structure design
211. Add and Search Word - Data structure design
Solutions
Store words in dictionary whose key is length of words, and value is a list of words.
search() requires length to be known, we can use this information to narrow down the search space
to words with the required length.
Binary Tree Level Order Traversal
102. Binary Tree Level Order Traversal
Solutions
Keep track of level of each node.
Append node to its corresponding level list.
199 post articles, 25 pages.