crack the code interview
文章平均质量分 50
yfdyyy
这个作者很懒,什么都没留下…
展开
-
crack the code interview 1.2
Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)void reverse(char * chr){ char * end = chr; while (*end !=原创 2013-11-27 22:43:42 · 458 阅读 · 0 评论 -
crack the code interview 3.4
#include using namespace std;struct StackNode{ int value; StackNode * next; StackNode(int v) { value = v; next = NULL; }};class Stack{private: StackNod原创 2013-12-16 21:27:40 · 452 阅读 · 0 评论 -
crack the code interview 3.5
//Implement a MyQueue class which implements a queue using two stacks.struct StackNode{ int value; StackNode * next; StackNode(int v) { value = v; next = NULL; }原创 2013-12-16 21:43:58 · 440 阅读 · 0 评论 -
crack the code interview 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.#include #define原创 2013-12-16 19:59:42 · 581 阅读 · 0 评论 -
crack the code interview 3.6
Write a program to sort a stack in ascending order. You should not make any assump-tions about how the stack is implemented. The following are the only functions thatshould be used to write this p原创 2013-12-17 22:15:35 · 523 阅读 · 0 评论 -
crack the code interview —— binarytree
#include using namespace std;struct BinaryTreeNode{ int value; BinaryTreeNode * left; BinaryTreeNode * right; BinaryTreeNode(int v) { value = v; left = right =原创 2013-12-17 22:17:12 · 443 阅读 · 0 评论 -
crack the code interview 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 mo原创 2013-12-17 22:16:20 · 612 阅读 · 0 评论 -
crack the code interview 4.7
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.#include using namespace std;stru原创 2014-03-11 20:08:02 · 569 阅读 · 0 评论 -
crack the code interview 4.4
Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists).#include #include原创 2014-03-11 20:05:39 · 649 阅读 · 0 评论 -
crack the code interview 4.5
Write an algorithm to find the ‘next’ node (i.e., in-order successor) of a given node in a binary search tree where each node has a link to its parent.#include using namespace std;struct T原创 2014-03-11 20:06:20 · 590 阅读 · 0 评论 -
crack the code interview 4.2
Given a directed graph, design an algorithm to find out whether there is a route between two nodes.#include #include #include using namespace std;enum State {unvisited, visited, visiti原创 2014-03-11 20:04:10 · 571 阅读 · 0 评论 -
crack the code interview 4.3
Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.#include using namespace std;struct TreeNode{ int value; TreeNode * left;原创 2014-03-11 20:05:02 · 362 阅读 · 0 评论 -
crack the code intervie 4.8
You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum up to that value. Note that it can be any path in the tree - it does not have to start原创 2014-03-11 20:08:41 · 738 阅读 · 0 评论 -
crack the code interview 3.1
//Describe how you could use a single array to implement three stacks.#include using namespace std;int stackSize = 900;int indexUsed = 0;//已经存放的value的个数int stackTop[3] = {-1, -1, -1};StackNode原创 2013-12-16 19:22:23 · 447 阅读 · 0 评论 -
crack the code interview 3.3
//Imagine a (literal) stack of plates. If the stack gets too high, it might topple. There-//fore, in real life, we would likely start a new stack when the previous stack exceeds//some threshold. Imp原创 2013-12-16 20:56:03 · 569 阅读 · 0 评论 -
crack the code interview 2.3
Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.这道题的意思是这样的,本来我们删除一个节点,需要将上一个节点的next指向这个节点的next,但是能,现在不能对上一个节点进行操作了,只能对这个节点进行操作。那么直接覆盖这个节原创 2013-12-04 18:09:32 · 441 阅读 · 0 评论 -
crack the code interview1.1
1.1. Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures? 我想到的是位图法。1.2 Write code to reverse a C-Style String. (C-St原创 2013-11-26 22:32:42 · 717 阅读 · 0 评论 -
crack the code interview1.3
Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two additional variables are fine. An extra copy of the array is not原创 2013-11-27 22:49:33 · 567 阅读 · 0 评论 -
crack the code interview 1.4
Write a method to decide if two strings are anagrams or not.这道题就是判断两个字符串是否由相同的字符组成,写一个简单一点的。void anagrams(char * s, chr * t){ char * start = s; int hitS[256] = {0}; while (*start != '原创 2013-11-27 22:52:03 · 744 阅读 · 0 评论 -
crack the code interview 1.5
Write a method to replace all spaces in a string with ‘%20’.char * replace(char * chr){ char * start = chr; int length = 0; int n_space = 0; while (*start != '\0') { len原创 2013-11-27 22:57:43 · 512 阅读 · 0 评论 -
crack the code interview 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?这题是一个矩阵的一个类似转置,给的答案是按照一个圈进行位置的替代。。原创 2013-11-27 23:02:57 · 615 阅读 · 0 评论 -
crack the code interview 1.7
Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.这道题的关键是不能直接进行set 0 操作,会把原来的数据冲掉,最后导致整个矩阵都是0,应该保存0的位置。只需要m+n个buffer就行了。void reset(int ** ma原创 2013-11-27 23:07:19 · 525 阅读 · 0 评论 -
crack the code interview 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 usingonly one call to isSubstring原创 2013-12-04 17:31:26 · 601 阅读 · 0 评论 -
crack the code interview 2.2
//Implement an algorithm to find the nth to last element of a singly linked list.struct LinkNode{ LinkNode * next; int value;}LinkNode * findLastN(LinkNode * head, int n){ int i = 1;原创 2013-12-04 17:54:54 · 503 阅读 · 0 评论 -
crack the code interview 2.1
Write code to remove duplicates from an unsorted linked list.不断的如果当前元素和前面的重复,删除当前元素。struct Node{ Node * next; int value;};void deleteDupNode(Node * head){ if (head == NULL)原创 2013-12-04 17:42:48 · 661 阅读 · 0 评论 -
crack the code interview 2.5
Given a circular linked list, implement an algorithm which returns node at the begin-ning of the loop.DEFINITIONCircular linked list: A (corrupt) linked list in which a node’s next pointer point原创 2013-12-04 21:11:31 · 457 阅读 · 0 评论 -
crack the code interview 4.6
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessarily a binary search tr原创 2014-03-11 20:06:58 · 509 阅读 · 0 评论