Solve a standard LeetCode easy-to-medium level algorithm problem within a 30-minute limit. Implement length_of_longest_substring(s) to return the length of the longest contiguous substring containing no repeated characters. Input is a string s, and output is an integer; explain the time and space complexity of your approach.
def length_of_longest_substring(s):