• leetcode5 Implement strstr() 实现strstr函数功能


      Implement strstr() 实现strstr函数功能

        whowhoha@outlook.com

    Question:

    Implement strstr(). Returns the index of the first occurrence of needle in haystack, or –1

    if needle is not part of haystack.

     

    int strStr(string haystack, string needle)

    {

            for (int i = 0; ; i++) {

                     for (int j = 0; ; j++) {

                             if (j == needle.length()) {

                                      return i;

                             }

                             if (i + j == haystack.length()) {

                                      return -1;

                             }

                             if (needle[j] != haystack[i + j]) {

                                      break;

                             }

                     }

            }

    }

  • 相关阅读:
    [solution]xdebug正确配置,但不显示错误信息
    SIGCHLD信号
    sigsuspend
    信号引起的竞态
    智力面试题
    可重入和不可重入
    信号—信号处理函数(捕捉)
    PCB信号集
    信号产生的原因:
    信号初步
  • 原文地址:https://www.cnblogs.com/whowhoha/p/5743287.html
Copyright © 2020-2023  润新知