Careercup | Chapter 4

二叉查换树,左孩子小于等于根,右孩子大于根。

完全二叉树,叶子都在最后一层,所有结点(除了叶子)都有两个孩子。

平衡二叉树,左右子树的高度在一定范围内。

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 differ by more than one.

4.2

Careercup | Chapter 4,布布扣,bubuko.com

时间: 2024-10-12 15:19:57

Careercup | Chapter 4的相关文章

Careercup | Chapter 6

6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring cups). How would you come up with exactly four quarts of water? Note that the jugs are oddly shaped, such that filling up exactly "half" of the

Careercup | Chapter 1

1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? 字符串问题,需要先确定是不是只有ASCII码. 如果是,可以用char[256],也可以用位向量.位向量的实现参照<编程珠玑>.i&MASK就是取余.i>>SHIFT就是取商. 1 class BitVector {

Careercup | Chapter 5

5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to insert M into Nsuch that M starts at bit j and ends at bit i. You can assume that the bits j through i have enough space to fit all ofM. That is, ifM= 100

Careercup | Chapter 8

8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can't handle the call, he or she must escalate the

CareerCup chapter 1 Arrays and Strings

1.Implement an algorithm to determine if a string has all unique characters What if you can not use additional data structures? The length of ACSII code of a character is 8, so we can build a array, the length is 260, to represent the hash table of a

Careercup | Chapter 3

3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满了之后,需要把相邻的栈调整好,这是一个递归的过程. 每个stack有一些属性,所以不妨将每个stack封闭起来,我这里是用一个private的struct来实现,方便,同时对外部又不可见. 对于一些常用的操作,比如环形数组取下一个数,前一个数,都可以封装起来. 1 class XNStack { 2

Careercup | Chapter 7

7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only the add operator. 比较简单.但是要封装得好. 7.5 Given two squares on a two-dimensional plane, find a line that would cut these two squares in half. Assume that th

CareerCup Chapter 4 Trees and Graphs

struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),right(NULL){} }; Not all binary trees are binary search trees. 4.1 Implement a function to check if a tree is balanced. For the purposes of this question

CareerCup之1.1字符串中字符判重

[题目] Chapter 1 | Arrays and Strings 原文: 1.1 Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? 译文: 实现一个算法来判断一个字符串中的字符是否唯一(即没有重复).不能使用额外的数据结构. (即只使用基本的数据结构) [分析] [思路一]首先,我们要搞清