Cracking the Coding Interview
selfimpr1991
这个作者很懒,什么都没留下…
展开
-
Chapter 2 | Linked Lists--返回单链表倒数第n个元素及删除中间的某个节点
2.2 Implement an algorithm to find the nth to last element of a singly linked list.译文:实现一个算法返回单链表中倒数第n个元素原创 2013-12-05 13:23:24 · 2607 阅读 · 0 评论 -
Chapter 4 | Trees and Graphs--判断有向图两节点之间是否存在路径
4.2 Given a directed graph, design an algorithm to find out whether thereis a route between two nodes.原创 2014-07-24 15:10:05 · 8689 阅读 · 0 评论 -
Chapter 2 | Linked Lists--查找循环链表中的环的开始结点
2.5 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.DEFINITIONCircular linked list: A (corrupt) linked list in which a node’s nextpointer poin原创 2013-12-21 10:00:26 · 3761 阅读 · 0 评论 -
Chapter 4 | Trees and Graphs--检查一棵树是否平衡以及判断一棵树是否为平衡二叉树
4.1 Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in distance from the root by mor原创 2014-04-08 17:03:29 · 1466 阅读 · 0 评论 -
Chapter 3 | Stacks and Queues--两个栈实现队列
3.5 Implement a MyQueue class which implements a queue using two stacks.译文:利用两个栈实现一个队列 MyQueue。都知道队列的特点是 “先进先出”(FIFO),栈的特点是 “先进后出”(FILO)。可以很简单的通过两个栈来实现一个队列,即实现队列,则先将数据压入第一个栈,然后依次弹出并压进第二个栈,随原创 2014-03-21 16:36:28 · 1163 阅读 · 0 评论 -
Chapter 3 | Stacks and Queues--栈解决汉诺塔问题
3.4 In the classic problem of the Towers of Hanoi, you have 3 rods and Ndisks of different sizes which can slide onto any tower. The puzzle starts with disks sorted in ascending order of size from to原创 2014-03-19 20:29:50 · 2644 阅读 · 0 评论 -
Chapter 3 | Stacks and Queues--实现数据结构模拟一个栈由几个子栈组成,并可以在指定子栈上进行出栈操作
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 newstack when the previous stack exceeds some threshold. Implemen原创 2014-03-17 21:54:10 · 1548 阅读 · 1 评论 -
Chapter 3 | Stacks and Queues--实现一个函数返回栈中的最小值,时间复杂度为O(1)
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, popand min should all operate in O(1) time.译文:实现一个栈,除了 push和 pop原创 2014-02-17 21:34:00 · 1421 阅读 · 0 评论 -
Chapter 3 | Stacks and Queues--一个数组实现三个栈
3.1 Describe how you could use a single array to implement three stacks.原创 2013-12-30 21:56:15 · 3101 阅读 · 0 评论 -
Chapter 3 | Stacks and Queues--一个数组实现三个栈(续)
针对上篇博文中方法二的问题,这里我们提供一个方法来解决所出现的空间浪费的问题上篇博文见:一个数组实现三个栈(1)方法二加强版:下面就针对这个问题对程序进行进一步的修改。1、每次 pop 出栈之后,检查压出元素位置是否小于当前数组总索引,如果是,则将总索引指向压出元素位置,就是指向刚弹出后留下的空位置,否则表示总索引位置在压出元素位置之前,那么就不需要进行处理;2、每次 push 压栈后原创 2013-12-31 12:01:53 · 2182 阅读 · 1 评论 -
Chapter 2 | Linked Lists--实现两个单链表数据的和
2.4 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 1’s digit is at the head of the list. Write a原创 2013-12-19 10:20:16 · 1171 阅读 · 0 评论 -
Chapter 1 | Arrays and Strings--判断变位词和字符串空格替换为‘ ’
1.4 Write a method to decide if two strings are anagrams or not.译文:写一个函数判断是否两个字符串为变位词。变位词就是两个字符串中的字符相同,只是位置不同这里似乎又涉及到了字符的重复问题,通过前面几个小节的说明,可以借助一个数组来表征字符的出现,不过这里是两个字符串,我们可以采用同一个数组,对一个字符串中的字符出现来原创 2013-11-27 18:44:58 · 1696 阅读 · 0 评论 -
Chapter 1 | Arrays and Strings--旋转N*N矩阵的图像和处理M*N矩阵,若某位置为0则所在行和列均置0
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?译文:给定一张表示成N*N矩阵的图像,图像中每个像素是4原创 2013-11-30 11:13:31 · 2454 阅读 · 0 评论 -
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?译文:实现一个算法来判断字符串中的字符是否唯一,不能使用额外的数据结构,即只可使用基本的数据结构首先,假定该字符集是含扩原创 2013-11-25 16:51:30 · 2313 阅读 · 0 评论 -
Chapter 2 | Linked Lists--移除未排序链表中的重复项
2.1 Write code to remove duplicates from an unsorted linked list. FOLLOW UP How would you solve this problem if a temporary buffer is not allowed?译文:从一个未排序的链表当中移除重复的项。进一步的,如原创 2013-12-03 20:05:18 · 1798 阅读 · 0 评论 -
Chapter 1 | Arrays and Strings--字符串的翻转与去重
1.2 Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.) 译文:写代码翻转C语言风格的字符串。(C语言风格意味着"abcd"需要5个字符来表示,包括最后的空字符)原创 2013-11-26 18:39:12 · 1965 阅读 · 0 评论 -
Chapter 1 | Arrays and Strings--旋转字符串的判断
1.7 Write an algorithm such that if an element in an M*N matrix is 0,its entire row and column is set to 0.译文:写一个算法来处理一个M*N矩阵,如果矩阵中某个元素为0,则将该元素所在行和列的元素均置0。这个属于简单型的。遍历一次矩阵,记录下元素为0的位置(行和列),第二次遍历原创 2013-11-30 16:58:56 · 2194 阅读 · 0 评论 -
Chapter 4 | Trees and Graphs--有序数组构建最小高度的二叉树
4.3 Given a sorted (increasing order) array, write an algorithm to createa binary tree with minimal height.译文:给定一个原创 2014-08-05 20:34:17 · 1678 阅读 · 0 评论