Leetcode 159 — Longest Substring with At Most Two Distinct Characters

The problem can be found here. This is essentially a duplicate for Leetcode 904 — Fruit Into Baskets.

With this problem, I try to take my solution (which takes O(n) time and O(n) space)…