Implement strStr()
Implement strstr
2023-09-27 14:27:03 时间
称号
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
方法
仅仅须要遍历一遍就可以。public String strStr(String haystack, String needle) { int lenH = haystack.length(); int lenN = needle.length(); if(lenH < lenN ){ return null; } for(int i = 0; i < lenH - lenN + 1; i ++){ int j = 0; while(j < lenN){ if(haystack.charAt(i + j) != needle.charAt(j)){ break; } j ++; } if(j == lenN){ return haystack.substring(i, lenH); } } return null; }
版权声明:本文博客原创文章,博客,未经同意,不得转载。
相关文章
- Web Api调用遇到错误提示System.Web.HttpException (0x80004005): The controller for path '' was not found or does not implement IController.
- How To Implement Forms-Based Authentication in Your ASP.NET Application by Using C#.NET
- LeetCode232 Implement Queue using Stacks Java 题解
- Think in ISP(image sensor pipe )之How to implement an effecitive AE
- How do I implement a cancelable event?
- 蒙特卡洛树搜索算法 —— github上的implement的原代码
- 【LeetCode】208. Implement Trie (Prefix Tree)
- 【LeetCode OJ 232】Implement Queue using Stacks
- LeetCode 232: Implement Queue using Stacks
- [LeetCode] 470. Implement Rand10() Using Rand7() 使用Rand7()来实现Rand10()
- [LeetCode] Implement Magic Dictionary 实现神奇字典
- [CareerCup] 3.1 Implement Three Stacks using Array 使用数组来实现三个栈
- [LeetCode] 28. Implement strStr() 实现strStr()函数
- [LeetCode] Implement Stack using Queues 用队列来实现栈
- leetcode 28. Implement strStr() 实现 strStr()(简单)