Java LeetCode Problem 1: Find First Occurrence in String

🚀 Day -10/100 #100DaysOfLeetCode 📌Problem-1 : Find the Index of the First Occurrence in a String. 🔗Problem Link : https://lnkd.in/gp6NbvNR 💡 Approach: To solve this problem, I needed to find the first occurrence of the substring needle inside the string haystack. 🔹 First, I checked whether haystack contains needle using the built-in contains() method. 🔹 If it exists, I returned the starting index using indexOf(). 🔹 If it does not exist, I returned -1. This approach ensures a simple and efficient solution by leveraging Java’s built-in string methods. #JavaProgramming #LeetCode #ProblemSolving #CodingJourney

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories