Outputs are different between LeetCode OJ and my personal computer


  • 0
    C

    Here is my solution:

    bool canCross(vector<int>& stones) {
            unordered_set<int> stones_(stones.begin(), stones.end());
            unordered_map<int, unordered_set<int>> dp;
            dp[0] = {0};
            for (int s: stones) {
                cout << s << ": ";
                for (auto& v: dp[s]) {
                    cout << v << " ";
                }
                cout << endl;
                for (auto& v: dp[s]) {
                    if (v > 0 && stones_.count(s + v)) {
                        dp[s + v].insert(v);
                    }
                    if (stones_.count(s + v + 1)) {
                        dp[s + v + 1].insert(v + 1);
                    }
                    if (v > 0 && stones_.count(s + v - 1)) {
                        dp[s + v - 1].insert(v - 1);
                    }
                }
            }
            return dp[stones.back()].size();
        }
    

    Here is the output of LeetCode OJ:
    0: 0 excape
    1: 1 excape
    2: 1 excape
    3: 1 2 excape
    4: 1 2 excape
    5: 1 2 excape
    6: 1 2 3 excape
    7: 1 2 3 excape
    8: 1 2 3 excape
    9: 1 2 3 excape
    10: 1 2 3 4 excape
    11: 1 2 3 4 excape
    12: 1 2 3 4 excape
    13: 1 2 4 excape
    14: 1 2 excape
    15: 1 2 excape
    Here is the output of my personal computer:
    (Apple LLVM version 8.1.0 (clang-802.0.42)
    Target: x86_64-apple-darwin16.4.0
    Thread model: posix)
    0: 0
    1: 1
    2: 1
    3: 1 2
    4: 1 2
    5: 1 2
    6: 1 2 3
    7: 1 2 3
    8: 1 2 3
    9: 1 2 3
    10: 1 2 3 4
    11: 1 2 3 4
    12: 1 2 3 4
    13: 1 2 3 4
    14: 1 2 3 4
    15: 1 2 3 4 5
    Thanks for help.


Log in to reply
 

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