Could someone tell me why my solution is so slow?


  • 0

    I thought re module is very fast, I'm very confused.

    class Solution:
        def strStr(self, haystack, needle):
            """
            :type haystack: str
            :type needle: str
            :rtype: int
            """
            import re
            s = re.search(needle, haystack)
            return s.start() if s else -1
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.