LeetCode 28 实现 strStr()
生活随笔
收集整理的這篇文章主要介紹了
LeetCode 28 实现 strStr()
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://leetcode-cn.com/problems/implement-strstr/
解決方案
class Solution {public int strStr(String haystack, String needle) {if (needle.length() == 0) {return 0;}for (int i = 0; i + needle.length() <= haystack.length(); i++) {boolean flag = true;for (int j = 0; j < needle.length(); j++) {if (haystack.charAt(i + j) != needle.charAt(j)) {flag = false;break;}}if (flag) {return i;}}return -1;} }總結
以上是生活随笔為你收集整理的LeetCode 28 实现 strStr()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode 26 删除有序数组中的
- 下一篇: LeetCode 29 两数相除