zoukankan      html  css  js  c++  java
  • leetcode 28 Implement strStr()

    class Solution {
    public:
        int strStr(string haystack, string needle) {
            if (needle.empty()) return 0;
            int m = haystack.size(), n = needle.size();
            if (m < n) return -1;
            for (int i = 0; i <= m - n; ++i) {
                int j = 0;
                for (j = 0; j < n; ++j) {
                    if (haystack[i + j] != needle[j]) break;
                }
                if (j == n) return i;
            }
            return -1;
        }
    };
  • 相关阅读:
    01
    py5.30
    py 5.28
    py5.25
    py 5.24
    py 5.22
    py5.21
    py 5.18
    py 5.17
    py 5.16
  • 原文地址:https://www.cnblogs.com/wangkun1993/p/6390318.html
Copyright © 2011-2022 走看看