随笔分类 - CareerCup
摘要:4.8 You have two very large binary trees: Tl, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree...
阅读全文
摘要:4.7 Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data struc...
阅读全文
摘要:4.6 Write an algorithm to find the'next'node (i.e., in-order successor) of a given node in a binary search tree. You may assume that each node has a l...
阅读全文
摘要:4.5 Implement a function to check if a binary tree is a binary search tree.LeetCode上的原题,请参见我之前的博客Validate Binary Search Tree 验证二叉搜索树。
阅读全文
摘要:4.4 Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll...
阅读全文
摘要:4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.这道题给了我...
阅读全文
摘要:4.2 Given a directed graph, design an algorithm to find out whether there is a route between two nodes.LeetCode和CareerCup中关于图的题都不是很多,LeetCode中只有三道,分别是...
阅读全文
摘要:4.1 Implement a function to check if a binary tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that t...
阅读全文
摘要:3.7 An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based o...
阅读全文
摘要:3.6 Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you ma...
阅读全文
摘要:3.5 Implement a MyQueue class which implements a queue using two stacks.LeetCode上的原题,请参见我之前的博客Implement Queue using Stacks 用栈来实现队列。
阅读全文
摘要:3.4 In the classic problem of the Towers of Hanoi, you have 3 towers and N disks of different sizes which can slide onto any tower. The puzzle starts ...
阅读全文
摘要:3.3 Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when ...
阅读全文
摘要:3.2 How would you design a stack which, in addition to push and pop, also has a function min which returns the minimum element? Push, pop and min shou...
阅读全文
摘要:3.1 Describe how you could use a single array to implement three stacks.这道题让我们用一个数组来实现三个栈,书上给了两种方法,第一种方法是定长分割 Fixed Division,就是每个栈的长度相同,用一个公用的一位数组buff...
阅读全文
摘要:2.7 Implement a function to check if a linked list is a palindrome.LeetCode上的原题,参见我之前的博客Palindrome Linked List 回文链表。
阅读全文
摘要:2.6 Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.DEFINITIONCircular linked list: A (corrup...
阅读全文
摘要:2.5 You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the ...
阅读全文
摘要:2.4 Write code to partition a linked list around a value x, such that all nodes less than x come before all nodes greater than or equal to x.LeetCode上...
阅读全文
摘要:2.3 Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.EXAMPLEInput: the node c from the li...
阅读全文