Sinple hashtable C#


  • 0
    D
    public class Solution {
    public int[] SingleNumber(int[] nums) {
        int[] result = {-1,-1};
            Hashtable singlelist = new Hashtable();
            if (nums.Length == 0 || nums == null) return result;
            else
            {
                foreach (int i in nums)
                {
                    if (singlelist.ContainsKey(i) == false)
                    {
                        singlelist.Add(i, 1);
                    }
                    else if (singlelist.ContainsKey(i) == true)
                    {
                        singlelist[i] = 2;
                    }
                }
            }
            int count = 0;
            foreach (int key in singlelist.Keys)
            {
                if (Convert.ToInt32(singlelist[key]) == 1)
                {
                    result[count] = key;
                    count++;
                }
            }
            return result;
    }
    

    }


  • 0
    H

    Not constant space complexity. It is not the right answer


Log in to reply
 

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