28. Implement strStr()
Input: haystack = "hello", needle = "ll"
Output: 2Input: haystack = "aaaaa", needle = "bba"
Output: -1# @param {String} haystack
# @param {String} needle
# @return {Integer}
def str_str(haystack, needle)
if !haystack.empty? && needle.empty?
return 0
end
if haystack.include?(needle)
return haystack.index(needle)
end
return -1
endLast updated