• 简易遍历 寻找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, 00));
        }

        
    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 + 10);
            } 
    else {
                
    return exec(str, i + 1, count + 1);
            }
        }
    }

  • 相关阅读:
    mysql常用函数
    主程Ry访谈录
    mongodb spring anno 查询
    mongodb 查询少少优化
    jquery table thead drop
    ubuntu 配置java,eclipse ,flex,zend,php,TomCat环境
    mongodb shell
    TCP/IP Sockets in Java 源码
    java 断点下载
    直线生成 DDA
  • 原文地址:https://www.cnblogs.com/huidaoli/p/3202670.html
Copyright © 2020-2023  润新知