示例#1
0
        # starting the inital point of window to index 0
        start = 0

        for end in range(len(string)):

            # Checking if we have already seen the element or not
            if string[end] in seen:

                # If we have seen the number, move the start pointer
                # to position after the last occurrence
                start = max(start, seen[string[end]] + 1)

            # Updating the last seen value of the character
            seen[string[end]] = end
            maximum_length = max(maximum_length, end - start + 1)
        return maximum_length


timer = Timer()
s = "eeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpveeydgwdykpv"

prob1 = timer.CalculateTime(Solution().lengthOfLongestSubstring, s)
# timer.Average(timerList)
# 10

prob2 = timer.CalculateTime(Solution().longestUniqueSubsttr, s)

print(f"Code 1: {prob1[0]} s,\n\t\t{prob1[1]}")
print(f"Code 2: {prob2[0]} ms,\n\t\t{prob2[1]}")