五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2771. Longest Non-decreasing Subarray From Two Arrays

2023-07-15 09:47 作者:您是打尖兒還是住店呢  | 我要投稿

You are given two?0-indexed?integer arrays?nums1?and?nums2?of length?n.

Let's define another?0-indexed?integer array,?nums3, of length?n. For each index?i?in the range?[0, n - 1], you can assign either?nums1[i]?or?nums2[i]?to?nums3[i].

Your task is to maximize the length of the?longest non-decreasing subarray?in?nums3?by choosing its values optimally.

Return?an integer representing the length of the?longest non-decreasing?subarray in?nums3.

Note:?A?subarray?is a contiguous?non-empty?sequence of elements within an array.

?

Example 1:

Input: nums1 = [2,3,1], nums2 = [1,2,1]

Output: 2

Explanation:

One way to construct nums3 is: nums3 = [nums1[0], nums2[1], nums2[2]] => [2,2,1]. The subarray starting from index 0 and ending at index 1, [2,2], forms a non-decreasing subarray of length 2. We can show that 2 is the maximum achievable length.

Example 2:

Input: nums1 = [1,3,2,1], nums2 = [2,2,3,4]

Output: 4

Explanation:

One way to construct nums3 is: nums3 = [nums1[0], nums2[1], nums2[2], nums2[3]] => [1,2,3,4]. The entire array forms a non-decreasing subarray of length 4, making it the maximum achievable length.

Example 3:

Input: nums1 = [1,1], nums2 = [2,2]

Output: 2

Explanation:?

One way to construct nums3 is: nums3 = [nums1[0], nums1[1]] => [1,1]. The entire array forms a non-decreasing subarray of length 2, making it the maximum achievable length.

?

Constraints:

  • 1 <= nums1.length == nums2.length == n <= 105

  • 1 <= nums1[i], nums2[i] <= 109

用數(shù)組dp[i][j]表示以數(shù)組j結(jié)尾到i位置的時候的最長子數(shù)組的長度,

每次去比較大小,然后依次去維護(hù)dp+1的信息即可;

如果都是不大于的,就容易出來0,所以還要初始化1.

下面是代碼:

這是大牛的代碼:

Runtime:?20 ms, faster than?54.72%?of?Java?online submissions for?Longest Non-decreasing Subarray From Two Arrays.

Memory Usage:?57.3 MB, less than?65.36%?of?Java?online submissions for?Longest Non-decreasing Subarray From Two Arrays.


LeetCode 2771. Longest Non-decreasing Subarray From Two Arrays的評論 (共 條)

分享到微博請遵守國家法律
石门县| 盐山县| 霍城县| 类乌齐县| 琼结县| 天祝| 敦煌市| 周至县| 邵武市| 辉县市| 台北县| 古丈县| 西华县| 金坛市| 濮阳市| 梁山县| 铁力市| 古丈县| 垫江县| 阜南县| 体育| 南木林县| 特克斯县| 灌阳县| 淮北市| 伊通| 南涧| 桦川县| 井陉县| 湘潭县| 太仆寺旗| 平罗县| 泽州县| 武宣县| 肃北| 呼玛县| 汝南县| 寿光市| 博乐市| 商南县| 巴彦县|