Difference between "run code" and "submit", C++


  • 0
    G

    For the life of me, I can't understand why there's a difference between "Run Code" and "Submit".
    I have read through the FAQ but no avail.
    I looked through the documentation of the different methods I'm using to look for undefined behavior, but didn't find such.

    class Solution {
    public:
        int maxCoins(vector<int>& nums) {
            list<int> numsl(nums.begin(), nums.end());
            return maxCoins(numsl);
        }
     
     private:   
        int maxCoins(list<int>& nums) {
            bool first = true;
            int _max = 0;
            for (auto it = nums.begin(); it != nums.end(); ++it) {
                int curr = *it;
                int value = curr;
                auto prev = it;
                if (!first) --prev;
                auto next = it;
                ++next;
                if (!first) curr *= *prev;
                if (next != nums.end()) curr *= *next;
                
                nums.erase(it);
                curr += maxCoins(nums);
                it = nums.insert(next, value);
                _max = std::max(curr, _max);
                
                first = false;
            }
            
            return _max;
        }
    
    };

  • 0
    G

    I have figured it out - I'm relying on "next" when re-inserting the removed element. However the "next" iterator could be invalidated by the recursive maxCoins call.
    It's still unclear to me, however, how come there's a different between RunCode and Submit.


Log in to reply
 

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