09 2015 档案

摘要:构造函数不能声明为虚函数,析构函数可以声明为虚函数,而且有时是必须声明为虚函数。不建议在构造函数和析构函数里面调用虚函数。构造函数不能声明为虚函数的原因是:构造一个对象的时候,必须知道对象的实际类型,而虚函数行为是在运行期间确定实际类型的。而在构造一个对象时,由于对象还未构造成功。编译器无法知道对象... 阅读全文
posted @ 2015-09-28 15:16 daijkstra 阅读(244) 评论(0) 推荐(0) 编辑
摘要:#include #include #include #include using namespace std;int edit(string str1, string str2){ int res; int n1 = str1.size(); int n2 = str2.size... 阅读全文
posted @ 2015-09-22 11:40 daijkstra 阅读(208) 评论(0) 推荐(0) 编辑
摘要:昨天今日头条笔试,发现好简单,一写出了几个问题,回来才想出来。一个长度不超过10000的整数数组,里面有若干个0,请事先一段代码,将数组中值为0的元素移动到数组的最前面,其余元素相对位置保持不变。#include #include using namespace std;// 此处忘记引用了void... 阅读全文
posted @ 2015-09-17 11:08 daijkstra 阅读(449) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/valid-number/使用if-else实现DFAclass Solution {public: bool isNumber(string s) { while(!s.empty() && s[0] == ' ') ... 阅读全文
posted @ 2015-09-16 13:55 daijkstra 阅读(202) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/single-number-iii/Given an array of numbersnums, in which exactly two elements appear only once and all the other elemen... 阅读全文
posted @ 2015-09-15 15:25 daijkstra 阅读(135) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/single-number-ii/Given an array of integers, every element appears three times except for one. Find that single one.在网上看... 阅读全文
posted @ 2015-09-15 14:44 daijkstra 阅读(549) 评论(0) 推荐(0) 编辑
摘要:依然二分,转向条件,容易出问题的地方。对于<=情况,截止区间是0;使用mid-1需要多进行一次查找通过left=mid+1修正区间;对于<情况,截止区间是1;使用right=mid可以直接得到正确区间。https://leetcode.com/problems/first-bad-version//... 阅读全文
posted @ 2015-09-15 10:51 daijkstra 阅读(164) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/implement-queue-using-stacks/class Queue {private: stack in,out; public: // Push element x to the back of queue... 阅读全文
posted @ 2015-09-14 16:26 daijkstra 阅读(230) 评论(0) 推荐(0) 编辑
摘要:class Solution {public: int nthUglyNumber(int n) { if(n k(n); k[0] = 1; for(int i = 1; i =1 阅读全文
posted @ 2015-09-06 15:25 daijkstra 阅读(654) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/h-index/class Solution {public: int hIndex(vector& citations) { priority_queue pq; for(int i=0;i= pages... 阅读全文
posted @ 2015-09-06 14:55 daijkstra 阅读(137) 评论(0) 推荐(0) 编辑