Missing test case?


  • 0
    H

    Do we allow negative input?
    When handling corner case "0", my program incorrectly assume if the data container only has one 0, then it will return false. But if we allow negative input, then it will not be true.
    An example test case would be add(0), add(-1), add(1), find(0)

    HashMap<Integer, Boolean> hs = new HashMap<Integer, Boolean>();
    // Add the number to an internal data structure.
    public void add(int number) {
        if(hs.containsKey(number)){
            hs.put(number, true);
        }else{
            hs.put(number, false);
        }
    }
    
    // Find if there exists any pair of numbers which sum is equal to the value.
    public boolean find(int value) {
        for(Integer i : hs.keySet()){
            if(hs.containsKey(value - i)){
                if(i != value -i){
                    return true;
                }else{
                    return hs.get(i);
                }
            }
        }
        
        return false;
    }

  • 0

    Thanks, you are right! I have just published your test cases.


Log in to reply
 

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