摘要://原文://// A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For practical and aesthetic reasons, each ...
阅读全文
摘要://原文://// Given a matrix in which each row and each column is sorted, write a method to find an element in it.// 从最右一排,从上到下,小于右上角的元素则下降,大于右上角的元素则左移找;...
阅读全文
摘要://原文://// Given a sorted array of strings which is interspersed with empty strings, write a method to find the location of a given string.////Example:...
阅读全文
摘要://Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log n) algorithm that finds an element in the array. ...
阅读全文
摘要://原文://// Write a method to sort an array of strings so that all the anagrams are next to each other.// 译文:// 写一个函数对字符串数组排序,使得所有的变位词都相邻。//参考@hawstein#...
阅读全文
摘要://原文://// You 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 o...
阅读全文
摘要:#include #include using namespace std;void mswap(int &a, int &b){ int c = a; a = b; b = c;}void print(int *a, int size){ for (int i = 0; i a[i+1]) {...
阅读全文
摘要://An array A[1…n] contains all the integers from 0 to n except for one number which is missing. In this problem, //we cannot access an entire integer ...
阅读全文
摘要://Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are...
阅读全文
摘要:#include #include using namespace std;int getNum1(int N){ int num=0; for (int i=0; i>1; } return num;}void print(int p) { vector v; for (int k = 0;k>...
阅读全文
摘要://Given a (decimal - e.g. 3.72) number that is passed in as a string, print the binary representation.If the number can not be represented accurately ...
阅读全文
摘要://You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M b...
阅读全文
摘要://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...
阅读全文
摘要://原文://// 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 s...
阅读全文
摘要://原文://// 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...
阅读全文
摘要://原文://// 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 ...
阅读全文
摘要://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, y...
阅读全文
摘要://Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height.//// 译文://// 给定一个有序数组(递增),写程序构建一棵具有最小高度的二叉树。...
阅读全文
摘要://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 lea...
阅读全文
摘要:#include #include using namespace std;class tree{public: tree() { //root = create(); root = NULL; } /***输入扩展层次遍历序列,#表示该节点为空***/ tree(char *s) { roo...
阅读全文
摘要:发现一篇神文,解决了困扰许久的远程桌面OpenGL/GPU 等问题。。。原地址在这:http://www.tanglei.name/how-to-run-gpu-programs-using-remote-connection/有时候往往需要通过远程桌面连接进行coding工作,像一般的比如web之...
阅读全文
摘要:// Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the o...
阅读全文
摘要://Implement a MyQueue class which implements a queue using two stacks.#include #includeusing namespace std;class MyQueue{public: stack data,buffer; My...
阅读全文
摘要://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 th...
阅读全文
摘要://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...
阅读全文
摘要:这题的思想来自于http://hawstein.com/posts/2.5.html,重新实现了一下用hash来记录循环的起点//Given a circular linked list, implement an algorithm which returns node at the beginn...
阅读全文
摘要:删除前面的linklist,使用node来表示链表// You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in rever...
阅读全文
摘要:#include #include using namespace std;class linklist{private: class node { public: node(){} string data; node * next; }; int size;public: node *he...
阅读全文
摘要:#include #include using namespace std;class linklist{private: class node { public: node(){} string data; node * next; }; node *head; int size;publi...
阅读全文
摘要:#include #include using namespace std;class linklist{private: class node { public: node(){} string data; node * next; }; node *first; int size;publ...
阅读全文
摘要://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 i...
阅读全文
摘要://Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.////这题原答案就是要两个buffer来记录出现0的位置。不知道有没可以不用buffe...
阅读全文
摘要://原文://// 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...
阅读全文
摘要://原文://// Write a method to replace all spaces in a string with ‘%20’.//#include using namespace std;char* replace(char * str){ if (str == NULL) { re...
阅读全文
摘要://Write a method to decide if two strings are anagrams or not.//// 变位词(anagrams)指的是组成两个单词的字符相同,但位置不同的单词。比如说, abbcd和abcdb就是一对变位词。// // 使用一个固定数组大小记录各个...
阅读全文
摘要://原文://// Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer. NOTE: One or two addi...
阅读全文