自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(27)
  • 收藏
  • 关注

转载 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 T1. A tree T2 is a subtree of T1 if there exi...

2014-07-13 10:10:00 69

转载 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. NOTE: This is not necessarily a binary searc...

2014-07-13 09:49:00 105

转载 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 each node during the recursive process...

2014-07-12 23:14:00 72

转载 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 D linked lists)./*Use BFS to travel the ...

2014-07-11 20:39:00 63

转载 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 same problem on leetcode,https://oj.leetc...

2014-07-11 19:04:00 50

转载 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 heights of the two subtrees of any node never ...

2014-07-11 18:10:00 59

转载 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 not copy the elements into any other data struc...

2014-07-10 22:14:00 77

转载 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, then push the element onstack1. when dequ...

2014-07-10 21:05:00 65

转载 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 previous stack exceeds some threshold. Implem...

2014-07-10 10:33:00 92

转载 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 all operate in O(1) time.A quite classical p...

2014-07-09 23:51:00 57

转载 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 disks sorted in ascending order of size from t...

2014-07-09 20:23:00 84

转载 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 Stacks*/import java.util.*;public c...

2014-07-09 18:26:00 66

转载 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 that we can destroy the list, reverse th...

2014-07-08 21:44:00 91

转载 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) linked list in which a node's next pointer poi...

2014-07-08 20:46:00 67

转载 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 digit is at the head of the list. Write a func...

2014-07-08 19:18:00 67

转载 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 additional pointer to store the nodes less than ...

2014-07-08 17:39:00 64

转载 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 list a->b->c->d->eResult: nothin...

2014-07-07 23:40:00 63

转载 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 one K nodes, then the two pointers form ...

2014-07-07 22:14:00 60

转载 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 HashSet to record whether a val has appear...

2014-07-07 21:14:00 70

转载 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 rotation of s1 using only one call to isSubst...

2014-07-06 20:14:00 67

转载 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 use the first row and first colown to reco...

2014-07-06 19:43:00 73

转载 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 this in place?Each time rotate 4 pixles (i, j...

2014-07-06 19:08:00 53

转载 CTCI 1.5

Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not bec...

2014-07-06 12:55:00 58

转载 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 additional characters, and that you are given ...

2014-07-05 20:20:00 63

转载 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 difference is that in 1.1 we just need to know w...

2014-07-05 17:56:00 102

转载 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 from the end to the start. The time complexity...

2014-07-05 15:28:00 62

转载 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 a string has all unique charachters, we nee...

2014-07-05 15:01:00 68

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除