您当前的位置: 首页 > 
  • 0浏览

    0关注

    674博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

模式匹配

沙漠一只雕得儿得儿 发布时间:2016-11-18 19:52:52 ,浏览量:0

package 字符串下;
/**
 * 暴力解决返回第一次匹配的字符串位置
 * @author buder_cp
 *
 */
public class 模式匹配 {
	public static int strStr(String haystack, String needle) {
		int m = haystack.length();
		int n = needle.length();
		for (int i = 0; i < m; i++) {
			int count = 0;
			for (int j = 0; j < n; j++) {
				if (haystack.charAt(i + j) != needle.charAt(j)) {
					break;
				} else {
					count++;
				}
			}
			if (count == n) {
				return i;
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		int k = strStr("qaz123345234243u68", "1233");
		System.out.println(k);
	}
}
关注
打赏
1657159701
查看更多评论
立即登录/注册

微信扫码登录

0.0378s