1 class Solution {
 2     /**
 3      * Returns a index to the first occurrence of target in source,
 4      * or -1  if target is not part of source.
 5      * @param source string to be scanned.
 6      * @param target string containing the sequence of characters to match.
 7      */
 8     public int strStr(String source, String target) {
 9         // write your code here
10         if (source == null && target == null){
11             return -1;
12         }
13         if (source == null){
14             return -1;
15         }
16         if (target == null){
17             return -1;
18         }
19         for (int i = 0; i < source.length() - target.length() + 1; i++){
20             int j = 0;
21             for ( ; j < target.length(); j++){
22                 if (source.charAt(i + j) != target.charAt(j)){
23                     break;
24                 }
25             }
26             if (j == target.length()){
27                     return i;
28                 }
29         }
30         return -1;
31     }
32 }

优质内容筛选与推荐>>
1、0902NOIP模拟测试赛后总结
2、collection time random os sys 序列化 subprocess 等模块
3、6.11
4、vc2015解决“错误 D8016 “/ZI”和“/Gy-”命令行选项不兼容 ”问题
5、理解函数表达式的函数名称


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号