170. Two Sum III - Data structure design

Description

Here

Intuition

按照find heavy和add heavy 讨论

Pitfall

find heavy的时候

  public boolean find(int value) {
    for (int other : valToCount.keySet()) {
      if (valToCount.containsKey(value - other)) {
        final int count = valToCount.get(value - other);
        if (value == other * 2) {
          // cannot directly return count > 1. Other candidates still have chance.
          if (count > 1) {
            return true;
          }
        } else {
          return true;
        }
      }
    }
    return false;
  }

Solution

results matching ""

    No results matching ""