1、KMP的部分匹配值表
/**
* 生成到一个字符串(子串) 的部分匹配值表
*
* @param str 传入空数组,子字符串
*/
public static void getNext(String str){
//创建一个 next 数组保存部分匹配值
int[] next = new int[str.length()];
//如果字符串长度为1 部分的匹配值就是0
next[0] = 0;
for (int i=1,j=0; i< str.length(); i++){
//当 dest.charAt(i) != dest.charAt(j) ,我们需要从 next[j-1]获取新的 j
//直到我们发现 有 dest.charAt(i) == dest.charAt(j)成立才退出
while (j > 0 && str.charAt(j) != str.charAt(i)) {
j = next[j - 1];
}
// 找到相同的前后缀,匹配值+1,不相同则不加
if (str.charAt(i) == str.charAt(j)){
j++;
}
next[i] = j;
}
}
2、取出整数的每一位进行操作
int n = 250;
//每一次循环取出个位上的数进行操作。
while (n > 0){
int temp = n % 10;
n = n/10;
}
3、取两个数的中间值
int mid = be+((end-be) >>1); // be头,end尾;>>1 除以2