GithubHelp home page GithubHelp logo

Comments (3)

baitian752 avatar baitian752 commented on May 23, 2024 1

I figure it out that I should put all the codes between the comments.

#
# @lc app=leetcode.cn id=1438 lang=python3
#
# [1438] 绝对差不超过限制的最长连续子数组
#


# @lc code=start
from sortedcontainers import SortedList


class Solution:
    def longestSubarray(self, nums: list[int], limit: int) -> int:
        s = SortedList()
        n = len(nums)
        left, right, ans = 0, 0, 0
        while right < n:
            s.add(nums[right])
            while s[-1] - s[0] > limit:
                s.remove(nums[left])
                left += 1
            ans = max(ans, len(s))
            right += 1
        return ans


# @lc code=end

This maybe work.

from vscode-leetcode.

woung717 avatar woung717 commented on May 23, 2024

sortedcontainers is not a Python standard library.

from vscode-leetcode.

baitian752 avatar baitian752 commented on May 23, 2024

sortedcontainers is not a Python standard library.

Please refer to https://support.leetcode.com/hc/en-us/articles/360011833974-What-are-the-environments-for-the-programming-languages

Language Version Notes
Python3 Python3.11 Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself. For Map/TreeMap data structure, you may use sortedcontainers library.

We can use sortedcontainers directly in the browser!

from vscode-leetcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.