<p>Given an integer array <code>nums</code>, return <code>true</code> if any value appears <strong>at least twice</strong> in the array, and return <code>false</code> if every element is distinct.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,1]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>

<p><strong>Explanation:</strong></p>

<p>The element 1 occurs at the indices 0 and 3.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,2,3,4]</span></p>

<p><strong>Output:</strong> <span class="example-io">false</span></p>

<p><strong>Explanation:</strong></p>

<p>All elements are distinct.</p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [1,1,1,3,3,4,3,2,4,2]</span></p>

<p><strong>Output:</strong> <span class="example-io">true</span></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class IntHashMap {
public:
    int m_size;
    int *m_HashMap;
    bool *m_Occupied;

    IntHashMap(int size) : m_size(size) {
        m_HashMap = new int[m_size]();
        m_Occupied = new bool[m_size]();
    }

    ~IntHashMap() {
        delete[] m_HashMap;
        delete[] m_Occupied;
    }

    bool AddElement(int value) {
        int position = (value % m_size + m_size) % m_size;  // Ensures non-negative index
        int loops = 0;
        while (m_Occupied[position] && loops != m_size) {
            if (m_HashMap[position] == value) {
                return false; // Duplicate found
            } else {
                position = (position + 1) % m_size;
                loops++;
            }
        }
        if (loops == this->m_size) {
            return false; // Map is full
        } else {
            m_HashMap[position] = value;
            m_Occupied[position] = true;
        }
        return true;
    }

    bool IsInMap(int value) {
        int position = (value % m_size + m_size) % m_size;  // Ensures non-negative index
        int loops = 0;
        while (m_Occupied[position] && loops != m_size) {
            if (m_HashMap[position] == value) {
                return true; // Value found
            } else {
                position = (position + 1) % m_size;
                loops++;
            }
        }
        return false; // Value not found
    }
};

class Solution {
public:
    bool containsDuplicate(vector<int>& nums) {
        IntHashMap hashMap(nums.size());
        for (int i = 0; i < nums.size(); i++) {
            if (hashMap.IsInMap(nums[i])) {
                return true;
            } else {
                hashMap.AddElement(nums[i]);
            }
        }
        return false;
    }
};

63003