The key point of O(n^2) algorithm

  • -2

    The key point is the comparing between double values.

    The most straightforward solution for me is counting the section(between two points) numbers on the lines.
    So I used a map to do that.

    typedef pair<double, double> LINE;
    map<LINE, int> lineSecNums;

    But sometime, I got the wrong answer. The algorithm is so simple. It couldn't be wrong. So I didn't give up. After a while thinking, I doubt that it needs a method to judge that if too pairs are the same line. So I redefine the map.

    struct LessLine{
       bool operator()(const LINE &l1, const LINE &l2){
    ... }
    map<LINE, int, LessLine> lineSecNums;

    Then it's accepted.

Log in to reply

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