| | | 1 | | // -------------------------------------------------------------------------------- |
| | | 2 | | // Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | | 3 | | // All Rights Reserved. |
| | | 4 | | // -------------------------------------------------------------------------------- |
| | | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | | 9 | | // known as Yevhenii Yeriemeieiv). |
| | | 10 | | // -------------------------------------------------------------------------------- |
| | | 11 | | |
| | | 12 | | namespace LeetCode.Algorithms.DesignHashMap; |
| | | 13 | | |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public sealed class DesignHashMapIntArray : IDesignHashMap |
| | | 16 | | { |
| | 1 | 17 | | private readonly int[] _items = new int[1_000_001]; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Time complexity - O(1) |
| | | 21 | | /// Space complexity - O(1) |
| | | 22 | | /// </summary> |
| | | 23 | | /// <param name="key"></param> |
| | | 24 | | /// <param name="value"></param> |
| | | 25 | | public void Put(int key, int value) |
| | 3 | 26 | | { |
| | 3 | 27 | | _items[key] = value + 1; |
| | 3 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Time complexity - O(1) |
| | | 32 | | /// Space complexity - O(1) |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="key"></param> |
| | | 35 | | /// <returns></returns> |
| | | 36 | | public int Get(int key) |
| | 4 | 37 | | { |
| | 4 | 38 | | return _items[key] - 1; |
| | 4 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Time complexity - O(1) |
| | | 43 | | /// Space complexity - O(1) |
| | | 44 | | /// </summary> |
| | | 45 | | /// <param name="key"></param> |
| | | 46 | | public void Remove(int key) |
| | 1 | 47 | | { |
| | 1 | 48 | | _items[key] = 0; |
| | 1 | 49 | | } |
| | | 50 | | } |