Thursday, March 24, 2016

LeetCode Q159: Longest Substring with At Most Two Distinct Characters (hard)

Given a string, find the length of the longest substring T that contains at most 2 distinct characters.
For example, Given s = “eceba”,
T is "ece" which its length is 3.

Solution:
To solve substring problem, could use following template:

My solution is:

A better solution is:

Round 2 solution:
Rnd3 sol:

No comments:

Post a Comment