zoukankan      html  css  js  c++  java
  • leetcode 1671

    前置题目是300, 对于每个数字, 求得包括其的左递增子序列长度, 和包括其的递减右子列长度, 相加减-即可.

    class Solution:
        def calculate_increase_num(self, nums):
            if not nums:
                return nums
            longest_val_list = []
            longest_index_list = []
            lis_list = []
    
            longest_val_list.append(nums[0])
            longest_index_list.append(0)
            lis_list.append(1)
    
            for i in range(1, len(nums)):
                val = nums[i]
    
                if val > longest_val_list[-1]:
                    longest_val_list.append(val)
                    longest_index_list.append(i)
                    lis_list.append(len(longest_val_list))
                    continue
                start = 0
                end = len(longest_val_list) - 1
                while start < end:
                    mid = (start + end) // 2
                    if longest_val_list[mid] >= val:
                        end = mid
                    else:
                        start = mid + 1
                longest_val_list[start] = val
                lis_list.append(start + 1)
            return lis_list
        def minimumMountainRemovals(self, nums: List[int]) -> int:
            left_increase_num_list = self.calculate_increase_num(nums)
            right_increase_num_list = self.calculate_increase_num(nums[::-1])[::-1]
            length = 0
            for i in range(len(left_increase_num_list)):
                a = left_increase_num_list[i]
                b = right_increase_num_list[i]
                if a == 1 or b == 1:
                    continue
                tmp = a + b - 1
                if tmp > length:
                    length = tmp
            result = len(left_increase_num_list) - length
            return result
    
  • 相关阅读:
    私有IP地址
    Python随手记
    Selenium+Python环境搭建
    FTP- Download, upload, Delete & find files
    初学Selenium遇上的问题
    automate sap遇上的一些问题
    LR常见问题
    服务器资源监控指标
    QTP场景恢复函数
    导出excel用例
  • 原文地址:https://www.cnblogs.com/mangmangbiluo/p/15586741.html
Copyright © 2011-2022 走看看