Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Monobilliards
- {
- public class Monobilliards : IMonobilliards
- {
- public bool IsCheater(IList<int> inspectedBalls)
- {
- var stack = new Stack<int>();
- var queue = new Queue<int>();
- foreach (var ball in inspectedBalls)
- queue.Enqueue(ball);
- for (int i = 1; i < inspectedBalls.Count+1; i++)
- {
- stack.Push(i);
- while (stack.Peek() == queue.Peek())
- {
- stack.Pop();
- queue.Dequeue();
- if ((stack.Count == 0) || (queue.Count == 0))
- break;
- }
- }
- return (stack.Count != 0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement