小编Drk*_*per的帖子

使用此实现,hashset.contains 如何成为 O(1)?

.Net 中的 HashSet.Contains 实现是:

    /// <summary>
    /// Checks if this hashset contains the item
    /// </summary>
    /// <param name="item">item to check for containment</param>
    /// <returns>true if item contained; false if not</returns>
    public bool Contains(T item) {
        if (m_buckets != null) {
            int hashCode = InternalGetHashCode(item);
            // see note at "HashSet" level describing why "- 1" appears in for loop
            for (int i = m_buckets[hashCode % m_buckets.Length] - 1; i >= 0; i = m_slots[i].next) {
                if (m_slots[i].hashCode == hashCode && …
Run Code Online (Sandbox Code Playgroud)

c# hashset time-complexity .net-core

6
推荐指数
1
解决办法
1300
查看次数

插入重复值linq

在一组价值观中

[0, 2, 25, 30]
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用linq

[0, 0, 0, 2, 2, 2, 25, 25, 25, 30, 30, 30] //Replicate 2 times (values repeated 3 times)
Run Code Online (Sandbox Code Playgroud)

有没有办法用linq做到这一点?

c# linq

5
推荐指数
1
解决办法
129
查看次数

标签 统计

c# ×2

.net-core ×1

hashset ×1

linq ×1

time-complexity ×1