安卓开发或者Java开发中经常使用Iterator遍历,尝试总结一下for配合get()的遍历和Iterator配合next()遍历的区别,进入Java的JDK源码中进行深度剖析一下...
分类:
其他好文 时间:
2014-09-11 13:58:12
阅读次数:
179
KMP算法中,如果当前字符匹配成功,即S[i]==T[j],令i++,j++,继续匹配下一个字符;如果匹配失败,即S[i] != T[j],需要保持i不变,并且让j = next[j],这里next[j] =1当匹配到S[i] != P[j]的时候有 S[i-j…i-1] = P[0…j-1]. 如...
分类:
其他好文 时间:
2014-09-10 23:40:31
阅读次数:
186
#include
#include
#include
using namespace std;
const int maxm = 40010;
const int maxn = 1010;
int first[maxn], cnt;
struct edge
{
int u, v, next;
}e[maxn*maxn];
int ans[maxm];
bool vis[maxm];
int...
分类:
其他好文 时间:
2014-09-10 22:30:11
阅读次数:
206
(1)从后往前,找到a[i] &num) { 4 int end = num.size() - 1; 5 int povit = end; 6 while(povit > 0){ 7 if(num[povit] > num[po...
分类:
其他好文 时间:
2014-09-10 22:25:01
阅读次数:
271
1 public class Solution { 2 public void connect(TreeLinkNode root) { 3 TreeLinkNode upperTravelingNode = root; 4 if (root==null) ...
分类:
其他好文 时间:
2014-09-10 21:06:51
阅读次数:
196
1 public class Solution { 2 public void connect(TreeLinkNode root) { 3 if (root==null) return; 4 TreeLinkNode upperLevelStartNode...
分类:
其他好文 时间:
2014-09-10 20:59:11
阅读次数:
156
题意:给你两个字符串,为你第一个字符串的前缀等于第二个字符串的后缀的最大长度是多少解题思路:KMP,两次匹配,不过方法比较巧妙,两次分开求next就行解题代码: 1 // File Name: getnext.cpp 2 // Author: darkdream 3 // Created Time:...
分类:
其他好文 时间:
2014-09-10 20:56:31
阅读次数:
169
题意:求一个字符串的所有前缀是否是复制出来的。解题思路:next 数值判断即可解题代码: 1 // File Name: getnext.cpp 2 // Author: darkdream 3 // Created Time: 2014年09月09日 星期二 22时35分02秒 4 5 #inc....
分类:
其他好文 时间:
2014-09-10 20:56:21
阅读次数:
229
题意:给你一串环形珠子,每串珠子有一种颜色,只能在队首或队末增加点,问你最少需要多少个株洲使得这串珠子颜色循环解题思路:其实从前面插入和从后面插入是一样的,所以我们只需要知道到了 len next指针的值就行解题代码: 1 // File Name: getnext.cpp 2 // Author:...
分类:
其他好文 时间:
2014-09-10 17:38:50
阅读次数:
114
链表结构:typedef struct ListNode{ int val; struct ListNode *next;}ListNode;1.判断一个单链表是否有环这个问题采用追击的方法,定义两个指针,一个一次走两步,一个一次走一步,如果相遇了就说明有环。int is_cycle(L...
分类:
其他好文 时间:
2014-09-10 14:08:30
阅读次数:
156