for (int i = 1; i < nums.size(); i++) {
dp[i] = 1;
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j] && dp[i] <= dp[j]) {
dp[i] = dp[j] + 1;
//maxLength = max(maxLength, dp[i]); why inside the loop??
}
}
maxLength = max(maxLength, dp[i]); // putting the check outside will avoid unnecessary check.
}