Careercup | Chapter 2】的更多相关文章

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就是取商. class BitVector { pu…
3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满了之后,需要把相邻的栈调整好,这是一个递归的过程. 每个stack有一些属性,所以不妨将每个stack封闭起来,我这里是用一个private的struct来实现,方便,同时对外部又不可见. 对于一些常用的操作,比如环形数组取下一个数,前一个数,都可以封装起来. class XNStack { pub…
链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow would you solve this problem if a temporary buffer is not allowed? 2.2 Implement an algorithm to find the kth to last element of a singly linked list.…
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…
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…
9.1 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 order. A has enough buffer at the end to hold B, we can merge two arrays from end to start index, like merg…
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…
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…
6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are given 31 dominos, and a single domino can cover exactly two squares. Can you use the 31 dominos to cover the entire board? Prove your answer (byprovid…
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…