Why TLE ???? Please help


  • 1
    L
    bool canJump(vector<int>& nums) {
        
        vector<bool> results(nums.size(), false);
        results[0] = true;
        
        for (int i = 1; i<nums.size(); i++) {
            for (int j = 0; j<i; j++) {
                if (results[j] && ((j+nums[j]) >= i)) {
                    results[i] = true;
                    break;
                }
            }
        }
        
        return results[nums.size()-1];
    }

  • 1
    H

    Hi laputa, you can change the second for loop statement to for(int j=i-1; j>=0; j--)


  • 0
    L

    Hi huanghaihui, I tried your suggestion, but still TLE. any other suggestion for DP solution?


Log in to reply
 

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