[Python3] dp
\n\nclass Solution:\n    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n        n = len(nums1)\n        dp = [[1]*2 for _ in rang
\n```\nclass Solution:\n    def maxNonDecreasingLength(self, nums1: List[int], nums2: List[int]) -> int:\n        n = len(nums1)\n        dp = [[1]*2 for _ in range(n)]\n        ans = 1\n        for i in range(n-2, -1, -1): \n            if nums1[i] <= nums1[i+1]: dp[i][0] = 1+dp[i+1][0]\n            if nums1[i] <= nums2[i+1]: dp[i][0] = max(dp[i][0], 1+dp[i+1][1])\n            if nums2[i] <= nums1[i+1]: dp[i][1] = 1+dp[i+1][0]\n            if nums2[i] <= nums2[i+1]: dp[i][1] = max(dp[i][1], 1+dp[i+1][1])\n            ans = max(ans, dp[i][0], dp[i][1])\n        return ans \n```
['Python3']