Tuesday, May 24, 2016

LeetCode 159: Longest Substring with At Most Two Distinct Characters

May 24, 2016

Work on the algorithm. The string "eoeab", the longest substring with at most two distinct characters is "eoe", and the length is 3.

1. Read the blog about solution:

http://yuanhsh.iteye.com/blog/2188917

Brute force solution:  O(n^3)

Sliding window  - better solution O(n) solution in time complexity

2. Study the code:

https://github.com/jianminchen/LeetCode-Java-Solutions/blob/master/159.longest-substring-with-at-most-two-distinct-characters.java

Write C# code:
https://gist.github.com/jianminchen/9061c12fee5e050e56a98cb3ffcc6f57





No comments:

Post a Comment