d*c
2 楼
干得漂亮!
c*a
3 楼
LZ下次出难点的题啊。
x*k
4 楼
pls implement a strstr() using kmp algorithm. thx
b*5
5 楼
kmp 没几行字吧。。。
int strstr(String haystack, String needle) {
int hLen = hayStack.length();
int nLen = needle.length();
int i = 0; int j = 0;
int[] next = new int[nLen];
preProcess(needle, next);
while (i < hLen && j < nLen) {
if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
else {
j = next[j];
}
}
if (j == nLen) return i-j;
else return -1;
}
void preProcess(String needle, int[] next) {
next[0] = -1;
int k = -1;
for (int j = 0; j < needle.length(); j++) {
if (k == -1 || needle.charAt(k) == needle.charAt(j)) {
k++; j++; next[j] = k;
}
else k = next[j];
}
【在 x****k 的大作中提到】
: pls implement a strstr() using kmp algorithm. thx
int strstr(String haystack, String needle) {
int hLen = hayStack.length();
int nLen = needle.length();
int i = 0; int j = 0;
int[] next = new int[nLen];
preProcess(needle, next);
while (i < hLen && j < nLen) {
if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
else {
j = next[j];
}
}
if (j == nLen) return i-j;
else return -1;
}
void preProcess(String needle, int[] next) {
next[0] = -1;
int k = -1;
for (int j = 0; j < needle.length(); j++) {
if (k == -1 || needle.charAt(k) == needle.charAt(j)) {
k++; j++; next[j] = k;
}
else k = next[j];
}
【在 x****k 的大作中提到】
: pls implement a strstr() using kmp algorithm. thx
c*n
6 楼
ft, 你copy paste 的还是自己写的? 都这样我没得饭吃了
【在 b**********5 的大作中提到】
: kmp 没几行字吧。。。
: int strstr(String haystack, String needle) {
: int hLen = hayStack.length();
: int nLen = needle.length();
: int i = 0; int j = 0;
: int[] next = new int[nLen];
: preProcess(needle, next);
: while (i < hLen && j < nLen) {
: if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
: else {
【在 b**********5 的大作中提到】
: kmp 没几行字吧。。。
: int strstr(String haystack, String needle) {
: int hLen = hayStack.length();
: int nLen = needle.length();
: int i = 0; int j = 0;
: int[] next = new int[nLen];
: preProcess(needle, next);
: while (i < hLen && j < nLen) {
: if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
: else {
j*o
7 楼
总有几个牛逼的三哥,但是你得确定最后来报道的是当初来面试的那个。
a*c
10 楼
全是藤校小本,水平确实不错。binary search 4 solutions 写的滴水不漏,面的老中
小中还没一个能100%一次写对的。最后只好问了几个无聊的数学公司,终于搞反了。不
过人家手上都有startup offer,来我们这纯粹就是免费旅游一趟。
下午又免了个火鸡白牛,光看胸我就给offer了。
小中还没一个能100%一次写对的。最后只好问了几个无聊的数学公司,终于搞反了。不
过人家手上都有startup offer,来我们这纯粹就是免费旅游一趟。
下午又免了个火鸡白牛,光看胸我就给offer了。
J*u
15 楼
三哥也在刷LC好不好,你们以为只有中国人在刷啊。。。我朋友说LC最大的访问源是。
。。。。。印度
。。。。。印度
c*e
16 楼
预处理的代码看着不对,for里面 j++,if (相等)里面也j++, 多加了
找到标准的一看,确实不对,for改成while,只判断终结,不做j++就对了
【在 b**********5 的大作中提到】
: kmp 没几行字吧。。。
: int strstr(String haystack, String needle) {
: int hLen = hayStack.length();
: int nLen = needle.length();
: int i = 0; int j = 0;
: int[] next = new int[nLen];
: preProcess(needle, next);
: while (i < hLen && j < nLen) {
: if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
: else {
x*k
17 楼
那就换个玩法吧
is it possible to move a imm 64 to a memory address using only one x86/64
instruction (based on intel xeon 64 bit cpu)? and explain why.
【在 b**********5 的大作中提到】
: kmp 没几行字吧。。。
: int strstr(String haystack, String needle) {
: int hLen = hayStack.length();
: int nLen = needle.length();
: int i = 0; int j = 0;
: int[] next = new int[nLen];
: preProcess(needle, next);
: while (i < hLen && j < nLen) {
: if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
: else {
is it possible to move a imm 64 to a memory address using only one x86/64
instruction (based on intel xeon 64 bit cpu)? and explain why.
【在 b**********5 的大作中提到】
: kmp 没几行字吧。。。
: int strstr(String haystack, String needle) {
: int hLen = hayStack.length();
: int nLen = needle.length();
: int i = 0; int j = 0;
: int[] next = new int[nLen];
: preProcess(needle, next);
: while (i < hLen && j < nLen) {
: if (haystack.charAt(i) == needle.charAt(j)) { i++; j++;}
: else {
相关阅读
请教onsite一道题微软的硬件工程师好转软件么 西雅图谁还记得这道面试题吗?remote 编程有人用过么,那个go to meeting需要注册么?1G内存读10G文件把握onsite的机会才是王道请教各位data mining和hadoop哪个方向更好?(给靠谱建议的回帖20美元相谢)大家怎么看storm8这个公司?share一点面经Developer Openings (.Net, MVC, SQL)有朋友h1b失业,黑下来3个月找到新工作成功transfer诚求意见 OPT Extension 搞杂了收到湾区小公司小Offer通知,求如何Negotiate关于leetcode上那个买卖股票II的问题VMware 面经顺求blessk sorted array merge大家现场写一个heap?写bugfree有困难的同学可以考虑看这本书求oracle,yahoo,saleforce和vmware的refer什么时候会要求background check?Linux device driver experice > 5years 求内推