Binary Search Tree Iterator问题:Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Cal...
分类:
其他好文 时间:
2015-03-13 20:32:54
阅读次数:
149
For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient.Input Spe...
分类:
其他好文 时间:
2015-03-13 18:39:26
阅读次数:
142
Persistence provider caller does not implement the EJB3 spec correctly. 实体bean发布出现的问题,将persistence.xml改为
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://...
分类:
其他好文 时间:
2015-03-13 16:45:21
阅读次数:
157
Given an array of integers, every element appears three times except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?...
分类:
其他好文 时间:
2015-03-12 22:35:49
阅读次数:
164
借助C语言中的库函数strstr,可以避免写KMP;循环判断即可。
#include
using namespace std;
int main()
{
char a[200001],b[100001];
int i,len;
bool f;
while(gets(a))
{
f=0;
gets(b);
if(strlen(b)>strlen(a)) cout<...
分类:
其他好文 时间:
2015-03-11 17:24:17
阅读次数:
117
O(n*m)的时间复杂度的算法好很容易实现, kmp的话O(n+m)的时间复杂度也行,但O(n*m)的时间复杂度的算法2ms就过了。。。int strStr(char *haystack, char *needle) { int index = -1,j; int lenhay = st...
分类:
其他好文 时间:
2015-03-10 21:27:09
阅读次数:
128
14.实现strStr():搜索一个字符串在另一个字符串中的第一次出现的位置
例:
#include
#include
int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
cout<<(*pch)<<endl;
return 0;
}...
分类:
编程语言 时间:
2015-03-10 10:26:24
阅读次数:
186
Implement pow(x, n).
思路:二分求,注意正负号就是了。
class Solution {
public:
double cal(double x, int n) {
if (n == 0)
return 1.0;
double tmp = pow(x, n>>1);
if (n & 1...
分类:
其他好文 时间:
2015-03-09 16:14:19
阅读次数:
161
1 题目Implement pow(x,n).Hide TagsMathBinary Search2 思路一开始想的是使用二分递归调用。要考虑n为负数的情况。时间是O(log(n)),比调用pow(x,n-1)要快很多。后来看了别人的思路,有一种bit位操作的,空间复杂度O(1)的算法。3 代码 ....
分类:
其他好文 时间:
2015-03-08 10:25:40
阅读次数:
155
用这题复习下kmp算法。kmp网上坑爹的是有很多种匹配方式,容易混淆,后人要警惕啊。这里对要查找的字符串的next全部置为-1,预处理时i和next[i-1]+1相比较。和http://kb.cnblogs.com/page/176818/ 这里相似。预处理完再匹配,第i个字符不匹配则比较第next[i-1]+1个。
class Solution{
public:
cha...
分类:
编程语言 时间:
2015-03-07 22:49:19
阅读次数:
202