如何快速判断一串数字中连零的个数。 注:不能用循环 谢谢

解决方案 »

  1.   

    不知道你说的是在那种语言我说一个通用的吧
    方法N多
    先获得总的长度replace ""
    在获得长度相减
      

  2.   

    听不懂……能清楚点不 for example……
      

  3.   

    indexOf(String str, int fromIndex) 
              返回指定子字符串在此字符串中第一次出现处的索引,从指定的索引开始。
    lastIndexOf(int ch) 
              返回指定字符在此字符串中最后一次出现处的索引。
    希望这两个方法能够帮助你我觉得用循环方便。
      

  4.   

    正则表达式没有直接看得到的循环,但是内部还是用循环了,只是你看不到布局:
    Pattern pattern = Pattern.compile("0+");
    Matcher matcher = pattern.matcher("123424000000123434");
    if (matcher.find()) { // 123424000000123434000123100如果这样的,每一个都要求出来,还得用循环。
    System.out.println(matcher.group() + ": " + matcher.group().length());
    }
      

  5.   

    我在美国要面试一家软件公司的实习机会,
    原题是这样的:
    How can you tell efficiently how many consecutive zero's are in a number without looping through its digits?
      

  6.   

    没有限制,我只是想了解下编程思想,呵呵
    我在美国要面试一家软件公司的实习机会,
    原题是这样的:
    How can you tell efficiently how many consecutive zero's are in a number without looping through its digits?
      

  7.   


    原题是这样的:
    How can you tell efficiently how many consecutive zero's are in a number without looping through its digits?
      

  8.   

    For Examplelong l = 1230000001;
    String test = l+"";
    System.out.println(test.length()-test.replaceAll("0*", "").length());
      

  9.   

    没限定什么语言:clojure (jvm):(map count (re-seq #"0+" "1234240000001234340010000020003"))
    (6 2 5 3)
      

  10.   

    Collections.max(Arrays.asList("1234240000001234340010000020003".split("[^0]+"))).length();
      

  11.   

    split方法好使,只是不能够确定找到的匹配项开始和结束的索引位置
      

  12.   

    int a = 1002300002;
    String b = a+"";
    String[] c = b.split("0");为什么用这个截取不到连续的0,只能截取一个