Implement strStr()
来源:互联网 发布:织梦cms使用手册 编辑:程序博客网 时间:2024/06/05 10:10
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
For example: source = “abcdefj”; target = “cde”, return 2
O(mn), 主要掌握双重for循环的写法。注意每次要先判断输入的合法性。KMP需要大致了解。复杂度是O(n)。
public int strstr(string source, string target){if( source == null || target == null ){<span style="white-space:pre"></span>return -1;<span style="white-space:pre"></span>}int i = 0, j = 0;for( i = 0; i < source.Length - target.Length + 1; i++ ){for ( j = 0; j < target.Length; j++ ){if( target(j) != source(i+j) ){<span style="white-space:pre"></span>break;<span style="white-space:pre"></span>}}if( j == target.Length ){return i;}}return -1;}
0 0
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Implement strStr()
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- 计算机博弈教程 连载【一. 计算机博弈简史】
- ASCII码表_完整版
- POJ 2737 Swamp Things (斜率判断多点共线)
- 如何为你的Android应用缩放图片
- Implement strStr()
- 刚刚学编程,写一点自己的想法
- linux下LNMP环境搭建
- Android Libraries You Should Use in Every Project
- vmware克隆Centos6.4虚拟机网卡无法启动问题
- Mac OS X网络诊断命令
- ZOJ 1094 Matrix Chain Multiplication
- 扯淡云计算
- nginx 和 php-fpm 通信使用unix socket还是TCP,及其配置