![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Cracking the coding interview
文章平均质量分 69
kingbird_Wang
努力奋斗中...
展开
-
两个已排序数组的归并
Cracking the coding interview 9.1You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.思路:从后向前归并。这里有个问题需要原创 2013-01-06 16:37:22 · 1229 阅读 · 0 评论 -
Anagrams 变位词
本文要讨论的是变位词,也就是说通过交换一个单词的各个字母的顺序能变成另一个单词,那么这两个单词互为变位词。问题一:判断给定的两个单词(标准ASCII)是否变位词方法一:用两个数组分别统计两个字符串里每个字符出现的个数,如果完全一致,则是变位词,否则不是.这个方法是大小写敏感的。这个方法能支持的输入字符串的最大长度 将受 用来统计字符个数的数组的类型 的限制。如果用unsigned ch原创 2013-01-09 15:40:52 · 1298 阅读 · 0 评论 -
二维数组中的查找 Cracking the coding interview 9.6
Cracking the coding interview 9.6Given a matrix in which each row and each column is sorted. write a method to find an element in it. 实现一个函数,在一个行列都排序的二维数组中查找某个元素是否存在。思路:如果待搜索元素小于一行中最左边的元素或者大于一行中最原创 2013-01-10 14:49:07 · 871 阅读 · 0 评论 -
判断一个二叉树是否是平衡二叉树 Cracking the coding interview 4.1
平衡二叉树的定义是:任意节点的左子树的高度和右子树的高度之差小于等于1.那么一个二叉树是平衡二叉树 当且仅当 (1,左子树是平衡二叉树, 2. 右子树是平衡二叉树; 3, 左右子树的高度之差小于等于1).所以用递归的方法判断的话,递归函数就需要返回两个信息:是否平衡,树高度. 代码如下。bool IsBalance(Node *pRoot, int & nDeepth){ if原创 2013-01-15 17:25:06 · 1882 阅读 · 0 评论 -
Rotated array related program. 和旋转数组相关的几个程序
问题一:将一个具有n个元素的数组向右旋转i个位置。EXAMPLE:Input: 将(1, 2, 3, 4, 5, 6, 7, 8, 9)旋转3个位置Output: (7, 8, 9, 1, 2, 3, 4, 5, 6)问题二:(Cracking the coding interview 9.3)Given a sorted array of n integers that原创 2013-01-08 17:36:43 · 10779 阅读 · 0 评论