uopspop

Untitled

Sep 5th, 2020
81
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×