Skip to content

Commit 2bc240a

Browse files
feat: solve Striver SDE Sheet problem 442 - Find the Index of the First Occurrence in a String
1 parent 9f1e149 commit 2bc240a

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Find the Index of the First Occurrence in a String (Easy)
2+
3+
**Problem ID:** 28
4+
**Problem Number:** 442
5+
**Link:** https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
6+
7+
## Problem Statement
8+
9+
Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
10+
11+
 
12+
Example 1:
13+
14+
15+
Input: haystack = "sadbutsad", needle = "sad"
16+
Output: 0
17+
Explanation: "sad" occurs at index 0 and 6.
18+
The first occurrence is at index 0, so we return 0.
19+
20+
21+
Example 2:
22+
23+
24+
Input: haystack = "leetcode", needle = "leeto"
25+
Output: -1
26+
Explanation: "leeto" did not occur in "leetco...
27+
28+
## Solutions
29+
30+
- Python: `solution.py`
31+
- Java: `solution.java`
32+
- JavaScript: `solution.js`
33+
34+
**Note:** Solutions need to be implemented.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Solution for Find the Index of the First Occurrence in a String
2+
// Problem ID: 28
3+
// Link: https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
4+
5+
class Solution {
6+
// TODO: Implement solution
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Solution for Find the Index of the First Occurrence in a String
2+
// Problem ID: 28
3+
// Link: https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
4+
5+
/**
6+
* TODO: Implement solution
7+
*/
8+
var solve = function() {
9+
// Implementation needed
10+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Solution for Find the Index of the First Occurrence in a String
2+
# Problem ID: 28
3+
# Link: https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
4+
5+
class Solution:
6+
def solve(self):
7+
# TODO: Implement solution
8+
pass

0 commit comments

Comments
 (0)