You are viewing a single comment's thread. Return to all comments →
C#:
public static string happyLadybugs(string b) { Dictionary<char, int> d = new Dictionary<char, int>(); foreach(char c in b) { if(!d.ContainsKey(c)) { d.Add(c, 0); } d[c]++; } bool has_ = false; foreach(var item in d) { if(item.Key != '_' && item.Value == 1) { return "NO"; } if(item.Key == '_') { has_ = true; } } if(!has_) { for(int i = 0; i < b.Count() - 1; i++) { if(b[i] != b[i+1] && (i != 0 && b[i] != b[i-1])) { return "NO"; } } } return "YES"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Happy Ladybugs
You are viewing a single comment's thread. Return to all comments →
C#: