Skip to content

Commit f319574

Browse files
committed
Added README.md file for Find the Index of the First Occurrence in a String
1 parent a60fdf9 commit f319574

File tree

1 file changed

+27
-0
lines changed
  • 28-find-the-index-of-the-first-occurrence-in-a-string

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<h2><a href="https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string">Find the Index of the First Occurrence in a String</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>Given two strings <code>needle</code> and <code>haystack</code>, return the index of the first occurrence of <code>needle</code> in <code>haystack</code>, or <code>-1</code> if <code>needle</code> is not part of <code>haystack</code>.</p>
2+
3+
<p>&nbsp;</p>
4+
<p><strong class="example">Example 1:</strong></p>
5+
6+
<pre>
7+
<strong>Input:</strong> haystack = &quot;sadbutsad&quot;, needle = &quot;sad&quot;
8+
<strong>Output:</strong> 0
9+
<strong>Explanation:</strong> &quot;sad&quot; occurs at index 0 and 6.
10+
The first occurrence is at index 0, so we return 0.
11+
</pre>
12+
13+
<p><strong class="example">Example 2:</strong></p>
14+
15+
<pre>
16+
<strong>Input:</strong> haystack = &quot;leetcode&quot;, needle = &quot;leeto&quot;
17+
<strong>Output:</strong> -1
18+
<strong>Explanation:</strong> &quot;leeto&quot; did not occur in &quot;leetcode&quot;, so we return -1.
19+
</pre>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Constraints:</strong></p>
23+
24+
<ul>
25+
<li><code>1 &lt;= haystack.length, needle.length &lt;= 10<sup>4</sup></code></li>
26+
<li><code>haystack</code> and <code>needle</code> consist of only lowercase English characters.</li>
27+
</ul>

0 commit comments

Comments
 (0)