Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the longest substring algorithm of unrepeated characters in big data

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to implement the longest substring algorithm without repeating characters in big data. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The longest substring without repeating characters

Train of thought answer

First define a pointer p to the chain head of the string, and then obtain the maximum length by whether the I character after the p pointer is the same as the j character after the p pointer. (also known as complete ergodic)

However, we are faced with a problem: if a string is particularly large, it will all be traversed, and the time complexity is O (n ^ 3). From this point of view, although it can solve the problem, it is too slow, and if the algorithm is not efficient, it will not make much sense.

Therefore, the following measures have been taken:

For example, to illustrate this measure, the string s is "dabcabcbb", when j points to the second "a" and I points to the first "a" when it is executed to j = 4, iDefin1. At this point, according to the previous traversal, the p pointer should be + 1 on ok, but if + 1, abca is a subset of dabca, so there is no need to judge this step, that is, you can omit this step! So the following optimizations are made:

Full traversal:

P = p + 1

After improvement:

P = p + I + 1

The complete code is as follows:

Int lengthOfLongestSubstring (char* s) {

Char* p = s

Int I = 0, j = 0, len = 0

For (j = 0; * (pairj)! ='\ 0mm; jacks +) {

For (I = 0; I)

< j; i++){ if(*(p+i) == *(p+j)){ p = p + i + 1; if(j >

Len) len = j

J = 0

Break

}

}

}

Len = (j > len)? J: len

Return len

}

Thank you for reading! This is the end of the article on "how to achieve the longest substring algorithm without repeating characters in big data". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report