In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to carry out the longest substring analysis of non-repetitive characters in JS,PY,TS version. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Description of item:
Given a string, please find out the length of the longest substring that does not contain repeating characters.
Example 1:
Enter: "abcabcbb"
Output: 3
Explanation: because the longest substring of non-repeating characters is "abc", its length is 3.
Example 2:
Enter: "bbbbb"
Output: 1
Explanation: because the longest substring of non-repeating characters is "b", its length is 1.
Example 3:
Enter: "pwwkew"
Output: 3
Explanation: because the longest substring of non-repeating characters is "wke", its length is 3.
Please note that your answer must be the length of the substring. "pwke" is a subsequence, not a substring.
Problem-solving ideas
The first idea after seeing this question is to loop, and then use HashMap to record the non-repetitive characters collected each time, and then define a record to record the subscript at the beginning of the collection. The subscript update judgment is whether the current HashMap has traversed characters, but the latter thought, since it is a judgment, there is no need to apply for additional space, because I have the subscript of the record record, so I only need to judge the original characters. It just so happens that the indexOf of JS is the same as the index of PY, so you can choose the location where the query starts, so remove the HashMap and query the original array directly, which really takes up less space.
JS version
/ * * @ param {string} s * @ return {number} * / const lengthOfLongestSubstring = s = > {let len = s.length if (len {let len: number = s.length if (len int: "": type s: str: int "" if len (s) ")
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.