内容中心

2026年比较好的氮气发生器口碑排行热门品牌推荐(实用)-苏州希特高纯气体设备有限公司

我公司座落于美丽的古城苏州,属江苏省民营科技企业;是中国工业气体会员单位,专门致力于设计、开发、制造 空气分离( 变压吸附制氮设备、PSA制氧设备、氮气纯化装置、氨分解制氢设备、氢氮配比装置等为一体的综合性企业。 我公司拥有现代化标准厂房以及高水平的专业技术人员和先进的检验、检测设备,公司始终坚持吸取国际先进技术,以科技为动力,大胆创新,在长期的发展过程中已形成自已独特的生产管理体系,在环保低碳的发展中产生近20项国家实用新型。经国家设备质量监督检验中心、江苏省通用机电产品检测院、江苏省技术监督局检测为合格产品。 公司以“以人为本,以质取胜,创新发展,诚信为主”为宗旨。提倡:为客户节约每一分成本,提高每一滴效益的设计、服务理念;即所有商业行为的开始就是我们为客户服务的开始!为客户提供经济、实用、高效的产品与及时周到的售后服务是我们的始终追求!相信我们质朴的经营理念定会为您创收更大的价值,欢迎各界朋友莅临参观、指导和业务治谈!

To solve this problem, we need to find the length of the longest substring without repeating characters in a given string. The optimal approach to this problem is using the sliding window technique combined with a hash set to efficiently track characters in the current window.

Approach

  1. Sliding Window Technique: We use two pointers (left and right) to represent the current window of characters being checked. The right pointer expands the window by moving to the right, while the left pointer contracts the window when a duplicate character is encountered.
  2. Hash Set: A set is used to keep track of characters in the current window. This allows O(1) time complexity for checking the presence of a character and adding/removing characters.
  3. Update Maximum Length: For each valid window (without duplicates), we update the maximum length of the window if it is larger than the current maximum.

Solution Code

def lengthOfLongestSubstring(s: str) -> int:
    char_set = set()
    left = 0
    max_len = 0

    for right in range(len(s)):
        # If current character is in the set, move left pointer to remove duplicates
        while s[right] in char_set:
            char_set.remove(s[left])
            left += 1
        # Add current character to the set
        char_set.add(s[right])
        # Update max length
        current_len = right - left + 1
        if current_len > max_len:
            max_len = current_len

    return max_len

Explanation

  • Initialization: We start with left pointer at 0, max_len at 0, and an empty set char_set.
  • Expanding the Window: The right pointer iterates over each character in the string. For each character:
    • If the character is already in the set, we move the left pointer to the right until the duplicate character is removed from the set.
    • We add the current character to the set.
    • We calculate the length of the current window (right - left +1) and update max_len if this length is greater than the current max_len.
  • Result: The max_len variable holds the length of the longest substring without repeating characters.

This approach ensures that each character is processed at most twice (once by the right pointer and once by the left pointer), leading to an O(n) time complexity, where n is the length of the string. The space complexity is O(k), where k is the number of distinct characters in the string. This is efficient and handles all edge cases, including empty strings and strings with all unique characters.

苏州希特高纯气体设备有限公司

苏州希特高纯气体设备有限公司



作者声明:本文包含人工智能生成内容。

在线客服

在线留言
您好,很高兴为您服务,可以留下您的电话或微信吗?