Advertisement
uopspop

Untitled

Sep 5th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. Implement strStr().
  2.  
  3. Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
  4.  
  5. Example 1:
  6.  
  7. Input: haystack = "hello", needle = "ll"
  8. Output: 2
  9. Example 2:
  10.  
  11. Input: haystack = "aaaaa", needle = "bba"
  12. Output: -1
  13. Clarification:
  14.  
  15. What should we return when needle is an empty string? This is a great question to ask during an interview.
  16.  
  17. For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().
  18.  
  19.  
  20.  
  21. Constraints:
  22.  
  23. haystack and needle consist only of lowercase English characters.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement