Why is C# not supported?


  • 0
    D
    public class AllOne
        {
            Dictionary<string, int> dict;
            SortedList<int, HashSet<string>> heap;
    
            public AllOne()
            {
                dict = new Dictionary<string, int>();
                heap = new SortedList<int, HashSet<string>>();
            }
    
            public void Increment(string key)
            {
                if (dict.ContainsKey(key))
                {
                    int heapKey = dict[key];
                    heap[heapKey].Remove(key);
                    dict[key] += 1;
                    heapKey++;
                    if (heap[heapKey] == null) heap[heapKey] = new HashSet<string> { key };
                    else heap[heapKey].Add(key);
                }
                else
                {
                    dict[key] = 1;
                    int heapKey = dict[key];
                    if (heap[heapKey] == null) heap[heapKey] = new HashSet<string> { key };
                    else heap[heapKey].Add(key);
                }
            }
    
            public void Decrement(string key)
            {
                if (!dict.ContainsKey(key)) return;
                int heapKey = dict[key];
                if (dict[key] == 1) dict.Remove(key);
                else dict[key] -= 1;
                heap[heapKey].Remove(key);
            }
    
            public string GetMaxKey()
            {
                if (heap.Count == 0) return string.Empty;
                return heap.Last().Value.FirstOrDefault();
            }
            public string GetMinKey()
            {
                if (heap.Count == 0) return string.Empty;
                return heap.First().Value.FirstOrDefault();
            }
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.