Example #1
0
        public void Test_Generic(string[] operations, int?[] inputs, object[] expected)
        {
            var set  = new RandomizedSet();
            var ret  = true;
            var retI = 0;

            for (int i = 0; i < operations.Length; i++)
            {
                switch (operations[i])
                {
                case "insert":
                    ret = set.Insert((int)inputs[i]);
                    Assert.AreEqual(ret, expected[i]);
                    break;

                case "remove":
                    ret = set.Remove((int)inputs[i]);
                    Assert.AreEqual(ret, expected[i]);
                    break;

                case "getRandom":
                    retI = set.GetRandom();
                    Assert.AreEqual(retI, retI);
                    break;
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            RandomizedSet obj = new RandomizedSet();

            Console.WriteLine(obj.Insert(0));
            Console.WriteLine(obj.Insert(1));
            Console.WriteLine(obj.Remove(0));
            Console.WriteLine(obj.Insert(2));
            Console.WriteLine(obj.Remove(1));
            Console.WriteLine(obj.GetRandom());
            //Console.WriteLine(obj.Remove(1));
            //Console.WriteLine(obj.Insert(2));
            //Console.WriteLine(obj.Remove(1));
            //Console.WriteLine(obj.Insert(1));
            //Console.WriteLine(obj.Insert(1));
            //Console.WriteLine(obj.GetRandom());
            //Console.WriteLine(obj.GetRandom());
        }