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(); } } }
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"); }
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"); }
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"); }
public void TestConstructor() { HashSet<Object> hs2 = new HashSet<Object>(); Assert.AreEqual(0, hs2.Size(), "Created incorrect HashSet"); }