can anyone help me figure out why my code show runtime error?


  • 0
    M

    this is my java code:

    public class Solution {
    	public int lengthOfLIS(int[] nums) {
            int[] dp = new int[nums.length];
            for(int i = 0; i < nums.length; i++) {
            	dp[i] = 1;
            }
            if(nums.length <= 1) return nums.length;
            for(int i = 1; i < dp.length; i++)
            	for(int j = 0; j < i; i++)
            		if(nums[j] < nums[i])
            			dp[i] = Math.max(dp[j]+1, dp[i]);
            int longest=dp[0];
            for(int i = 0; i < nums.length; i++) longest = Math.max(longest, dp[i]);
            return longest;
    	}
    
    }
    

    when i click "run button", i shows Runtime Error, this error message is :
    Runtime Error Message:
    Line 10: java.lang.ArrayIndexOutOfBoundsException: 8
    , but i really don't find any mistakes in line 10, so any one could find me why my code is wrong?


Log in to reply
 

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