[0] give the runtime error, instresting!


  • 0
    M

    class Solution {
    public:
    bool canJump(int A[], int n) {

        m_num = n;
        if(n == 1)return true;
        else if(A[0] == 0)return false;
        for (int i = 0; i < n; i++) {
            
            for (int j = 1 ; j <= A[i]; j++) {
                int high = i + j;
                if (high < n) {
                    table[i][high] = 1;
                }
            }
        }
        
        return dfs(0);
    }
    

    private:
    int m_num;
    int table[1200][1200];

    bool dfs(int row){
        if (row == m_num -1) {
            return true;
        }
        for (int i = 0; i < m_num; i++) {
            if ( 1 == table[row][i]) {
                if(dfs(i)) return true;
            }
        }
        
        return false;
    }
    

    };


Log in to reply
 

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