07 2014 档案
CTCI 4.8
摘要:You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of ...
阅读全文
CTCI 4.7
摘要:Design an algorithm and write code to find the first common ancestory of two nodes in a binary tree. Avoid storing additional nodes in data structure....
阅读全文
CTCI 4.5
摘要:Implement a function to check if a binary tree is a binary search tree./* The inorder travel of a BST is strictly increasing. We track the pre node of...
阅读全文
CTCI 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 have...
阅读全文
CTCI 4.3
摘要:Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.There is a...
阅读全文
CTCI 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 the h...
阅读全文
CTCI 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 may no...
阅读全文
CTCI 3.5
摘要:Implement a MyQueue class which implements a queue using two stacks./*Use two stacks, when enqueue, first pop all the elements in stack2 on stack1, th...
阅读全文
CTCI 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 the ...
阅读全文
CTCI 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 should a...
阅读全文
CTCI 3.4
摘要:In the classic problem of the Towers of Hanoi, you have 3 towers and Ndisks of different sizes which can slide onto any tower.The puzzle starts with d...
阅读全文
CTCI 3.1
摘要:Describe how you could use a single array to implement three stacks.Divide the array into three fixed parts, each stands for a stack./*Fixed Size Stac...
阅读全文
CTCI 2.7
摘要:Implement a function to check if a linked list is a palindrome.Reverse the second half of the list and then compare it with the first half./* Assume t...
阅读全文
CTCI 2.6
摘要:Given a circular linked list, implement an algorithm which returns the node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) l...
阅读全文
CTCI 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 Ts d...
阅读全文
CTCI 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.Use two addit...
阅读全文
CTCI 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 linked...
阅读全文
CTCI 2.2
摘要:Implement an algorithm to find the kth to last element of a singly linked list.Classical "Runner" Technique of linkedlist/*Use two pointers, forward o...
阅读全文
CTCI 2.1
摘要:Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed?/* Use a H...
阅读全文
CTCI 1.8
摘要:Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a ...
阅读全文
CTCI 1.7
摘要:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0.There is a same problem in leetcode. We could...
阅读全文
CTCI 1.6
摘要:Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do th...
阅读全文
CTCI 1.5
摘要:Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc...
阅读全文
CTCI 1.4
摘要:Write a method to replace all spaces in a string with'%20'. You may assume that the string has sufficient space at the end of the string to hold the a...
阅读全文
CTCI 1.3
摘要:Description: Given two strings, write a method to decide if one is a permutation of the other.We could use the same idea from CTCI 1.1. The only diffe...
阅读全文
CTCI 1.2
摘要:Since I mainly use Java, this problem seems meaning less for me to implement it with Java. Just use StringBuilder to append each character in string f...
阅读全文
CTCI 1.1
摘要:Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structure?In order to know whether ...
阅读全文
|
|