You are viewing a single comment's thread. Return to all comments →
using regex. the easiest way i could think of.
static int alternate(string s) { int max = 0; var hset = new string(s.Distinct().ToArray()); string tmp; for (int i = 0; i < hset.Length; i++) { for (int j = i + 1; j < hset.Length; j++) { tmp = Regex.Replace(s, @"[^" + hset[i] + hset[j] + "]", ""); if (tmp.Length > max && !Regex.IsMatch(tmp, @"([a-z])\1+")) max = tmp.Length; } } return max; }
Two Characters
You are viewing a single comment's thread. Return to all comments →
using regex. the easiest way i could think of.