# Leetcode 300. Longest Increasing Subsequence ###### tags: `Leetcode(JAVA)` 題目 : https://leetcode.com/problems/longest-increasing-subsequence/ 。 想法 : LIS。 類似走樓梯,每一次都多一個字元加進陣列,前方所有的字元都有機會跳到新的那一個字元。 時間複雜度 : O(n^2)。 程式碼 : (JAVA) ``` class Solution { public int lengthOfLIS(int[] nums) { int l=nums.length, ans=1; int[] dp=new int[2510]; for(int i=0 ; i<l ; i++){ dp[i]=1; } for(int i=0 ; i<l ; i++){ for(int j=0 ; j<=i ; j++){ if(nums[i]>nums[j]){ dp[i]=Math.max(dp[i], dp[j]+1); ans=Math.max(ans, dp[i]); } } } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up