<commit_before><commit_msg>3. Longest Substring Without Repeating Characters<commit_after>import unittest


class Solution(object):
    def lengthOfLongestSubstring(self, s):
        """
        :type s: str
        :rtype: int
        """
        counts = [0] * 128
        max_len = 0
        lo = 0

        for hi in xrange(len(s)):
            hi_ch = ord(s[hi])
            counts[hi_ch] += 1

            if counts[hi_ch] > 1:
                new_len = hi - lo
                if new_len > max_len:
                    max_len = new_len

                while True:
                    lo_ch = ord(s[lo])
                    lo += 1
                    counts[lo_ch] -= 1
                    if lo_ch == hi_ch:
                        break

        return max(max_len, len(s) - lo)


class Test(unittest.TestCase):
    def test(self):
        self._test('abcabcbb', 3)
        self._test('bbbbb', 1)
        self._test('pwwkew', 3)
        self._test('abc', 3)
        self._test('abcad', 4)

    def _test(self, s, expected):
        actual = Solution().lengthOfLongestSubstring(s)
        self.assertEqual(actual, expected)


if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.1132713440405748, 'fraction_numerical': 0.013524936601859678, 'mean_word_length': 1.4564315352697095, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6548128', 'n_tokens_mistral': 392, 'n_tokens_neox': 363, 'n_words': 85}