Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args) {
- int[] frequency1 = new int[26];
- var s = reader.ReadLine();
- int[] frequency2 = new int[s.Length + 1];
- int diffChars = 0;
- foreach (char c in s) {
- int ci = c - 'a';
- frequency2[frequency1[ci]]--;
- frequency1[ci]++;
- if (frequency1[ci] == 1) {
- diffChars++;
- }
- frequency2[frequency1[ci]]++;
- }
- int minF2I = int.MaxValue;
- int maxF2I = int.MinValue;
- foreach (int fq in frequency1) {
- if (fq == 0)
- continue;
- minF2I = Math.Min(minF2I, fq);
- maxF2I = Math.Max(maxF2I, fq);
- }
- if (maxF2I == minF2I || minF2I == 1 && frequency2[maxF2I] == diffChars - 1 || (maxF2I - minF2I == 1 && frequency2[maxF2I] == 1)) {
- writer.Write("YES");
- }
- else {
- writer.Write("NO");
- }
- writer.Flush();
- writer.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement