Exemple #1
0
    public int LengthOfLongestSubstring(string s)
    {
        int count = 0;
        var set   = new HashSet <Char>();

        for (int i = 0; i < s.Length; i++)
        {
            if (!set.Add(s.CharAt(i)))
            {
                count = set.Size();
            }
        }
    }
Exemple #2
0
        public void TestConstructorIF()
        {
            HashSet<Object> hs2 = new HashSet<Object>(5, (float) 0.5);
            Assert.AreEqual(0, hs2.Size(), "Created incorrect HashSet");

            try
            {
                new HashSet<Object>(0, 0);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.Fail("Failed to throw ArgumentException for initial load factor <= 0");
         }
Exemple #3
0
        public void TestConstructorI()
        {
            HashSet<Object> hs2 = new HashSet<Object>(5);
            Assert.AreEqual(0, hs2.Size(), "Created incorrect HashSet");

            try
            {
                new HashSet<Object>(-1);
            }
            catch (ArgumentException)
            {
                return;
            }

            Assert.Fail("Failed to throw ArgumentException for capacity < 0");
         }
Exemple #4
0
 public void TestConstructorCollection()
 {
     HashSet<Object> hs2 = new HashSet<Object>(Arrays.AsList(objArray));
     for (int counter = 0; counter < objArray.Length; counter++)
     {
         Assert.IsTrue(hs.Contains(objArray[counter]), "HashSet does not contain correct elements");
     }
     Assert.IsTrue(hs2.Size() == objArray.Length, "HashSet created from collection incorrect size");
 }
Exemple #5
0
 public void TestConstructor()
 {
     HashSet<Object> hs2 = new HashSet<Object>();
     Assert.AreEqual(0, hs2.Size(), "Created incorrect HashSet");
 }