内容中心

2026年靠谱的室内全景门厂家最新推荐-中山莱博顿卫浴有限公司

中山莱博顿卫浴有限公司(neptum),专业从事高档淋浴房、全景门、光波房、浴缸、智能镜/美妆镜柜、电热毛巾架、地漏、壁龛及浴室配件的研发、设计、制造和销售,是中山淋浴房协会创会会员和会长单位之一。 公司位于广东省中山市板芙经济开发区、火炬技术开发区,现拥有两个厂区,总占地面积110余亩,研发生产基地140000余平方米,拥有员工600余人,具备年产150万套生产能力。国际市场分布全球 80 多个国家和地区,与多个世界 500 强企业合作。国内一、二线城市设立了400多家专卖店。莱博顿以精湛工艺与定制化解决方案,成为众多高端民宿与星级酒店信赖的合作伙伴。 莱博顿全面实行软件系统管理,以ERP系统为中台,从全流程采购管理平台SRM到高级生产排程系统APS,车间管理系统MES再到品质管理系统OMS,实现从原材料采购到成品生产的全数字化智能管理;公司拥有行业的智能立体仓库,运用WMS仓储管理、PDA扫码管理和CRM客户管理系统,同时采用企业微信+OA自动化办公系统,真正实现经销商掌上了解订单进度,全面提升企业管理效能。凭借强大的研发队伍,强大的非标设计制造能力,科学的生产管理,树立良好形象

To solve this problem, we need to find the length of the longest substring in a given string that contains at most k distinct characters. This is a classic sliding window problem where we maintain a window of characters and adjust its size to meet the condition of having at most k distinct characters.

Approach

  1. Sliding Window Technique: We use two pointers (left and right) to represent the current window of characters.
  2. Hash Map: A hash map (dictionary) is used to keep track of the count of each character within the current window.
  3. Adjust Window: As we expand the window using the right pointer, we check if the number of distinct characters exceeds k. If it does, we shrink the window from the left until the number of distinct characters is within the limit.
  4. Max Length: We keep updating the maximum length of the valid window as we iterate through the string.

Solution Code

from collections import defaultdict

def lengthOfLongestSubstringKDistinct(s: str, k: int) -> int:
    char_count = defaultdict(int)
    left = 0
    max_len = 0

    for right in range(len(s)):
        char = s[right]
        char_count[char] += 1

        # Shrink the window if the number of distinct characters exceeds k
        while len(char_count) > k:
            left_char = s[left]
            char_count[left_char] -= 1
            if char_count[left_char] == 0:
                del char_count[left_char]
            left += 1

        # Update the maximum length of the valid window
        max_len = max(max_len, right - left + 1)

    return max_len

Explanation

  1. Initialization: We start with left pointer at 0, max_len set to 0, and a char_count dict to track character counts.
  2. Expand Window: For each character at the right pointer, we increment its count in the dict.
  3. Shrink Window: If the number of distinct characters in char_count exceeds k, we move the left pointer to the right, decrementing the count of the character at the left pointer. If the count becomes zero, we remove the character from the dict.
  4. Update Max Length: After adjusting the window, we check if the current window length (from left to right) is the longest valid window so far and update max_len accordingly.

Complexity

  • Time Complexity: O(n), where n is the length of the string. Each character is processed at most twice (once by the right pointer and once by the left pointer).
  • Space Complexity: O(k), since the dict can hold at most k+1 characters (we shrink the window when it exceeds k).

This approach efficiently finds the longest substring with at most k distinct characters using the sliding window technique, ensuring optimal performance.

中山莱博顿卫浴有限公司

中山莱博顿卫浴有限公司



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

在线客服

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