@@ -0,0 +1,1150 @@
+import unittest%0A%0A%0Aclass Solution(object):%0A    def checkInclusion(self, s1, s2):%0A        %22%22%22%0A        :type s1: str%0A        :type s2: str%0A        :rtype: bool%0A        %22%22%22%0A        counts1 = %5B0%5D * 128%0A        counts2 = %5B0%5D * 128%0A        lo = 0%0A%0A        for ch in s1:%0A            counts1%5Bord(ch)%5D += 1%0A%0A        for hi, hi_ch in enumerate(s2):%0A            hi_ch = ord(hi_ch)%0A            counts2%5Bhi_ch%5D += 1%0A            if counts2%5Bhi_ch%5D == counts1%5Bhi_ch%5D:%0A                if hi - lo + 1 == len(s1):%0A                    return True%0A            else:%0A                while counts2%5Bhi_ch%5D %3E counts1%5Bhi_ch%5D:%0A                    counts2%5Bord(s2%5Blo%5D)%5D -= 1%0A                    lo += 1%0A%0A        return False%0A%0A%0Aclass Test(unittest.TestCase):%0A    def test(self):%0A        self._test('ab', 'eidbaooo', True)%0A        self._test('ab', 'eidboaoo', False)%0A        self._test('aab', 'eidabbaooo', False)%0A        self._test('aab', 'eidaaabooo', True)%0A        self._test('adc', 'dcda', True)%0A%0A    def _test(self, s1, s2, expected):%0A        actual = Solution().checkInclusion(s1, s2)%0A        self.assertEqual(actual, expected)%0A%0A%0Aif __name__ == '__main__':%0A    unittest.main()%0A

567. Permutation in String. O(n). Sliding window