算法87题

来源:互联网 发布:淘宝商家多发货 编辑:程序博客网 时间:2024/04/29 14:15

求最大连续递增数字串(如“ads3sl456789DF3456ld345AA”中的“456789”)

public static String FindMaxSequence(String s){char[] chars = s.toCharArray();int max = 0;int end = -1;int pre = 0;for(int i = 0; i< chars.length; i++){if(chars[i] >= '0' && chars[i] <= '9'){pre++;if(pre > max){max = pre;end = i;}}elsepre = 0;}if(max > 0){return s.substring(end - max + 1, end);}elsereturn null;}


原创粉丝点击