简易遍历 寻找0/1串中 连续10个1首次出现位置(递归)
//A1.java
public class A1 {
private final static int N = 10;
public static void main(String[] args) {
String str = "0010000110111101011010101000101001110111000110010001111010111100011000011111111110100100001111110001101011010001000101011100011100111000110010010111100101101011100010110100111010000001000101110101111000001111100110101010010101011011010110011010101000111011001001110111000011001110111001100010001001010100111001111111110100000110001100010101101000011111011000011111111101100000010000000111111000000101111011110101101110101101100100001011110110010110111001110110001011110000111100000000010011101100101010101100101110000011100100010000101100101001001001000101001100010100011000110001011010101010000101000111000101011100111011101101110010100110001011011100110001110010010010101101111001101101100100100011001110111111110100001001001110101101100111101101000110000101000111000001011111010000110000011110001111100100010011100001010111011110011011101010101011011101100011110001101011110100011100011100110111110010101110011101000000011100111000111001001101000011100011001110100110110100111100111011000000011000";
System.out.println("index:" + exec(str, 0, 0));
}
public static int exec(String str, int i, int count) {
if (count == N) {
System.out.println("i:" + i);
return i - 10;
}
if (i == str.length()) {
return -1;
}
if (str.charAt(i) == '0') {
return exec(str, i + 1, 0);
} else {
return exec(str, i + 1, count + 1);
}
}
}
相关文章
- C语言-5月11日 如何判断一个数为素数,并遍历出一个区间内的所有素数
- 二叉树的非递归先序,中序,后序遍历
- 二叉树前序、中序和后序遍历的非递归实现
- neo4j遍历和图算法
- jQuery 遍历 - closest() 方法使用【转】
- LeetCode_螺旋遍历_中等_54.螺旋矩阵
- leetcode105 前序中序遍历序列构造二叉树
- 折纸的折痕(RVL中序遍历)
- 二叉树遍历
- vue中v-for遍历数组
- LeetCode·105.从前序与后序遍历序列构造二叉树·递归
- 二叉树的非递归遍历
- java递归实现文件夹文件的遍历输出
- python遍历数组的方法小结
- 大数据必学语言Scala(二十一):函数式编程 遍历 foreach
- [LeetCode] 145. Binary Tree Postorder Traversal 二叉树的后序遍历
- 数据结构:二叉树遍历非递归遍历和线索化
- leetcode404-----简单的树的遍历
- leetcode 144 145 94二叉树的三种非递归遍历
- leetcode 144 145 94二叉树的三种递归遍历