Solved LeetCode program · 28 of 1,000
#0028 · Find the Index of the First Occurrence in a String
Original English source
The word is "sadbutsad". The needle is "sad". The wordlength is the number of characters in word. The needlelength is the number of characters in needle. The final is wordlength minus needlelength. The answer is -1.
For every position from 0 to final.
The finish is position plus needlelength. The piece is the slice of word from position to finish. If piece is needle, set answer to position, display answer, then stop.
If answer is -1, display -1.
Expected stdout
0