@@ -0,0 +1,1018 @@
+import unittest%0A%0A%0Aclass Solution(object):%0A    def strStr(self, haystack, needle):%0A        %22%22%22%0A        :type haystack: str%0A        :type needle: str%0A        :rtype: int%0A        %22%22%22%0A        # Naive string search algorithm%0A        for haystack_start in xrange(len(haystack) - len(needle) + 1):%0A            for needle_index, needle_char in enumerate(needle):%0A                if needle_char != haystack%5Bhaystack_start + needle_index%5D:%0A                    break%0A            else:%0A                return haystack_start%0A        return -1%0A%0A%0A# See also: CPython fast search%0A# https://github.com/python/cpython/blob/master/Objects/stringlib/fastsearch.h%0A%0Aclass Test(unittest.TestCase):%0A    def test(self):%0A        self._test('abcdefghi', 'def', 3)%0A        self._test('abcdefghi', 'xyz', -1)%0A        self._test('abcdefghi', 'dez', -1)%0A%0A    def _test(self, haystack, needle, expected):%0A        actual = Solution().strStr(haystack, needle)%0A        self.assertEqual(actual, expected)%0A%0A%0Aif __name__ == '__main__':%0A    unittest.main()%0A

28. Implement strStr(). Naive