- 博客(11)
- 资源 (1)
- 收藏
- 关注
原创 Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).给定两个sort以后的数组,求两个数组中的中位数。
2014-04-28 14:25:33 720
原创 Search a 2D Matrix
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each
2014-04-22 12:39:35 535
原创 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically
2014-04-22 00:27:48 404
原创 函数参数进栈以及自增运算在函数调用中的trick
之前看到个题目int k = 1;printf("%d,%d\n",k,k++);答案显而易见是2 1, 因为函数调用时,参数的进栈顺序是从右向左,所以是先将k++进栈,即此时第二个参数值是1,但是k已经自增为2于是我就抱着好玩儿的心态试试:int k = 1;printf("%d,%d\n",++k,++k);我预期的结果是3 2但是结果是3 3我有点
2014-04-03 19:27:38 1356
原创 寻找第k个丑数
Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7.一个数的质因数只有3,5和7,找出第k个这样的数。
2014-04-03 19:10:23 817
原创 Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devis
2014-04-02 21:56:48 631
原创 显式调用析构函数
今天在复习shallow copy和deep copy的时候,为了重现shallow copy带来的问题,我写了下面一段代码class Node{public: int *num; Node(){num = new int[100];for(int i=0;i<100;i++) num[i]=0;} ~Node(){delete[] num;cout<<"destruct"<<en
2014-04-02 20:07:16 1527
原创 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()
2014-04-01 20:14:15 551
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人