my approach was to use bottom-up --finding the depth of the subtrees for each node--. I used recursion for the approach
- if root is None:
- return 0
- leftHeight = self.maxDepth(root.left)
- rightHeight = self.maxDepth(root.right)
my approach was to use bottom-up --finding the depth of the subtrees for each node--. I used recursion for the approach
my original approach was to use a dictionary(obviously) and then to use a double-ended queue(deque) for the LRU operation. It worked but it was only about 5% efficient and I couldn't accept that. So I went web surfing for another faster method, then I saw the Doubly-Linked list method which was wayy easier and faster because the "moving to the front" and "removing LRU" part in deques involves shifting(slower) which is O(n) time. While the same task in the doublly linked list takes O(1) time
my approach is to use a create a copy of the list without the random value yet..while making it; i will use a dictionary to map each address to a node(for o(1) access). Since all the nodes have been created, then I will map their random pointers using the dictionary to get each node.
my approach is to use a dictionary that connects a key(str) to a list(for value and timestamp)
my approach is simple, have a stack, pop from the top, go through the current node swap the children, check if the children exists; if it does, add it to a stack
question is very simple, i will go thorugh the numbers, add the unknown ones in a map and if it is in the map return it
I used an approach using 2 pointers such that one moves n + 1 distance from the other. They then both travel one node each until the faster one gets to the end. By this method the slow pointer is directly behind the fast one such that we can just remove it from the linked list by putting the next to the one after the node to-be-deleted. I used a dummy node to point to the head for simplification
dummy node and point its next attribute to the head. This handles edge cases, such as removing the first node of the list.To reorder the linked list as required, we need to rearrange the nodes by taking one from the front and then one from the back, continuing this alternation until the list is fully reordered.We split the list in half, reverse the second half, and then merge both halves by alternating nodes. This ensures we maintain the original relative ordering while meeting the required pattern.
My approach is to move through the linked list and check if it is in a set; if it is there return true. Else add it to the map.
head pointer to traverse the list.I am proud to say i solved this myself.