Q003 Longest Substring
a b c a b c b b
| |
| i cursor
start
We need 3 pointers, use sliding window [i, cursor] to check if there is any repeating element
Once found repeating element, update max length could be found within the sliding window,
and move start to the element next to the repeated element.
Then start the next round of sliding window
Example solution
https://github.com/Sylvia-YiyinShen/Algorithm/blob/master/SlidingWindow/Q003LongestSubstring.playground/Contents.swift
No comments:
Post a Comment