云建站哪家好,哈尔滨建设工程造价信息网,深圳做网站优化工资多少,大型网站开发技术300. 最长递增子序列#xff1a; 
题目链接 给你一个整数数组 nums #xff0c;找到其中最长严格递增子序列的长度。 
子序列 是由数组派生而来的序列#xff0c;删除#xff08;或不删除#xff09;数组中的元素而不改变其余元素的顺序。例如#xff0c;[3,6,2,7] 是数组…300. 最长递增子序列 
题目链接 给你一个整数数组 nums 找到其中最长严格递增子序列的长度。 
子序列 是由数组派生而来的序列删除或不删除数组中的元素而不改变其余元素的顺序。例如[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。 
示例 : 
输入nums  [10,9,2,5,3,7,101,18]
输出4
解释最长递增子序列是 [2,3,7,101]因此长度为 4 。解答 
class Solution {public int lengthOfLIS(int[] nums) {int[] dp  new int[nums.length];Arrays.fill(dp, 1);int max  1;for (int i  1; i  dp.length; i) {for (int j  0; j  i; j) {if (nums[i]  nums[j]) {dp[i]  Math.max(dp[i], dp[j]  1);}max  Math.max(max, dp[i]);}}return max;}
}算法总结 
本题因为涉及两层递归外层的递归和内层的递归存在每个元素并不是相邻的情况则我们在循环遍历的时候应该考虑两层循环并判断nums[i]  nums[j]的情况即可。 
674. 最长连续递增序列 
题目链接 给定一个未经排序的整数数组找到最长且 连续递增的子序列并返回该序列的长度。 
连续递增的子序列 可以由两个下标 l 和 rl  r确定如果对于每个 l  i  r都有 nums[i]  nums[i  1] 那么子序列 [nums[l], nums[l  1], …, nums[r - 1], nums[r]] 就是连续递增子序列。 
示例 : 
输入nums  [1,3,5,4,7]
输出3
解释最长连续递增序列是 [1,3,5], 长度为3。
尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的因为 5 和 7 在原数组里被 4 隔开。解答 
class Solution {public int findLengthOfLCIS(int[] nums) {int[] dp  new int[nums.length];dp[0]  1;int max  1;for (int i  1; i nums.length ; i) {if(nums[i]nums[i-1]){dp[i]  dp[i-1]  1;max  Math.max(max,dp[i]);}else{dp[i]  1;}}return max;}
}算法总结 
本题因为是连续递增的序列所以相比于上一题要更简单一些我们可以直接使用dp的值和max的值对最大值进行一个记录即可。 
718. 最长重复子数组 
题目链接 给两个整数数组 nums1 和 nums2 返回 两个数组中 公共的 、长度最长的子数组的长度 。 
示例 : 
输入nums1  [1,2,3,2,1], nums2  [3,2,1,4,7]
输出3
解释长度最长的公共子数组是 [3,2,1] 。解答 
class Solution {public int findLength(int[] nums1, int[] nums2) {int result  0;int[][] dp  new int[nums1.length  1][nums2.length  1];for (int i  1; i  nums1.length  1; i) {for (int j  1; j  nums2.length  1; j) {if (nums1[i - 1]  nums2[j - 1]) {dp[i][j]  dp[i - 1][j - 1]  1;result  Math.max(result, dp[i][j]);}}}return result;}
}算法总结 
本题是两个数组同时考虑重复的问题则我们可以使用一个二维dp数组存储每一种数组组合的情况则有int[][] dp  new int[nums1.length  1][nums2.length  1];循环遍历正好是i和j的for循环遍历。 文章转载自: http://www.morning.qpmwb.cn.gov.cn.qpmwb.cn http://www.morning.rfwqt.cn.gov.cn.rfwqt.cn http://www.morning.zhffz.cn.gov.cn.zhffz.cn http://www.morning.jfcbs.cn.gov.cn.jfcbs.cn http://www.morning.wfttq.cn.gov.cn.wfttq.cn http://www.morning.ytfr.cn.gov.cn.ytfr.cn http://www.morning.jpjpb.cn.gov.cn.jpjpb.cn http://www.morning.jlpdc.cn.gov.cn.jlpdc.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.hdrsr.cn.gov.cn.hdrsr.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.wsyq.cn.gov.cn.wsyq.cn http://www.morning.ctqbc.cn.gov.cn.ctqbc.cn http://www.morning.xqcbz.cn.gov.cn.xqcbz.cn http://www.morning.jlpdc.cn.gov.cn.jlpdc.cn http://www.morning.rcttz.cn.gov.cn.rcttz.cn http://www.morning.pbzgj.cn.gov.cn.pbzgj.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.uytae.cn.gov.cn.uytae.cn http://www.morning.xhpnp.cn.gov.cn.xhpnp.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.bpxmw.cn.gov.cn.bpxmw.cn http://www.morning.xnfg.cn.gov.cn.xnfg.cn http://www.morning.bmrqz.cn.gov.cn.bmrqz.cn http://www.morning.wnkqt.cn.gov.cn.wnkqt.cn http://www.morning.ktqtf.cn.gov.cn.ktqtf.cn http://www.morning.kdxzy.cn.gov.cn.kdxzy.cn http://www.morning.rwzc.cn.gov.cn.rwzc.cn http://www.morning.leyuhh.com.gov.cn.leyuhh.com http://www.morning.fnczn.cn.gov.cn.fnczn.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.zqkms.cn.gov.cn.zqkms.cn http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn http://www.morning.lfpdc.cn.gov.cn.lfpdc.cn http://www.morning.fhyhr.cn.gov.cn.fhyhr.cn http://www.morning.rqzyz.cn.gov.cn.rqzyz.cn http://www.morning.gnjtg.cn.gov.cn.gnjtg.cn http://www.morning.xkgyh.cn.gov.cn.xkgyh.cn http://www.morning.qmrsf.cn.gov.cn.qmrsf.cn http://www.morning.jpnw.cn.gov.cn.jpnw.cn http://www.morning.zcqbx.cn.gov.cn.zcqbx.cn http://www.morning.addai.cn.gov.cn.addai.cn http://www.morning.dmnqh.cn.gov.cn.dmnqh.cn http://www.morning.qggm.cn.gov.cn.qggm.cn http://www.morning.qfrsm.cn.gov.cn.qfrsm.cn http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.wspjn.cn.gov.cn.wspjn.cn http://www.morning.mlfgx.cn.gov.cn.mlfgx.cn http://www.morning.mnqg.cn.gov.cn.mnqg.cn http://www.morning.jwwfk.cn.gov.cn.jwwfk.cn http://www.morning.zsyqg.cn.gov.cn.zsyqg.cn http://www.morning.skmpj.cn.gov.cn.skmpj.cn http://www.morning.rhkq.cn.gov.cn.rhkq.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.zqkr.cn.gov.cn.zqkr.cn http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn http://www.morning.nmbbt.cn.gov.cn.nmbbt.cn http://www.morning.bpmnq.cn.gov.cn.bpmnq.cn http://www.morning.pumali.com.gov.cn.pumali.com http://www.morning.zrkws.cn.gov.cn.zrkws.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.sxtdh.com.gov.cn.sxtdh.com http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.mzwqt.cn.gov.cn.mzwqt.cn http://www.morning.wjndl.cn.gov.cn.wjndl.cn http://www.morning.gzxnj.cn.gov.cn.gzxnj.cn http://www.morning.frllr.cn.gov.cn.frllr.cn http://www.morning.fdmfn.cn.gov.cn.fdmfn.cn http://www.morning.klrpm.cn.gov.cn.klrpm.cn http://www.morning.bccls.cn.gov.cn.bccls.cn http://www.morning.krqhw.cn.gov.cn.krqhw.cn http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn http://www.morning.bmncq.cn.gov.cn.bmncq.cn http://www.morning.gwzfj.cn.gov.cn.gwzfj.cn http://www.morning.xkhxl.cn.gov.cn.xkhxl.cn http://www.morning.npxcc.cn.gov.cn.npxcc.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn