摘要: Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Write 阅读全文
posted @ 2017-02-22 18:05 Tsunami_lj 阅读(164) 评论(0) 推荐(0) 编辑
摘要: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other. Given an integer n, return all 阅读全文
posted @ 2017-02-22 15:03 Tsunami_lj 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 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 i 阅读全文
posted @ 2017-02-21 21:23 Tsunami_lj 阅读(220) 评论(0) 推荐(0) 编辑
摘要: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled 阅读全文
posted @ 2017-02-21 19:32 Tsunami_lj 阅读(152) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4],t 阅读全文
posted @ 2017-02-20 22:17 Tsunami_lj 阅读(78) 评论(0) 推荐(0) 编辑
摘要: typedef struct {char flag[3];short value;} sampleStruct;union{char flag[3];short value;} sampleUnion; 假设 sizeof(char)=1,sizeof(short)=2,那么sizeof(sampl 阅读全文
posted @ 2017-02-20 17:32 Tsunami_lj 阅读(323) 评论(0) 推荐(0) 编辑
摘要: Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two 阅读全文
posted @ 2017-02-20 15:14 Tsunami_lj 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 构造函数不能声明为虚函数,析构函数可以声明为虚函数,且有时候必须声明为虚函数。构造函数和析构函数都不能调用虚函数。 先析构子类再析构父类,如果父类析构函数有虚函数,会导致调用子类的已经析构的内容。 先构造父亲类再构造子类,如果父类构造函数有虚函数,会导致调用子类还没构造的内容。 A:构造函数不能声明 阅读全文
posted @ 2017-02-19 16:59 Tsunami_lj 阅读(461) 评论(0) 推荐(0) 编辑
摘要: ++运算符的对象必须是左值,而(x+y),(a-b--)这样的表达式是右值(arthmetic expressions are rvalues),常量9也是右值(rvalues),所以不满足条件。 类的大小只与成员变量(非static数据成员变量)和虚函数指针有关,和普通成员函数无关,如果有多个虚函 阅读全文
posted @ 2017-02-18 16:06 Tsunami_lj 阅读(1360) 评论(0) 推荐(0) 编辑
摘要: 已知二叉树先序后序的基础上,可以构造出不唯一的二叉树集。主要思路如下: 先序遍历中刚遍历到的下一个节点是后序遍历中最后遍历的节点,所以可以将后序遍历拆分成两个子序列,从而进行递归构造。 例如 先序遍历为aebdc,后序遍历为bcdea。 首先可以确定根节点为a,在后序中找先序的下一个节点(也就是e) 阅读全文
posted @ 2017-02-16 11:36 Tsunami_lj 阅读(472) 评论(0) 推荐(0) 编辑