Nine Chapters count judges Net-original website
http://www.jiuzhang.com/problem/34/
Topics
There is a 01 string consisting of only 0 and 1, where the longest substring is found, making the number of 0 and 1 in the substring equal
Answer
If 0 is considered as 1, then the substring we are looking for is the longest and the substring of 0. The problem of this seed string summation is generally solved by prefix and method. With Sum[i] representing the number of the first I and, the problem of the model converted to, find I and J, meet Sum[i] and sum[j] equal, and |i-j| the largest. Using a hash table as a secondary data structure, the hash table records the smallest i when a sum is obtained. Traverse Sum[i] From left to right, look in the hash table for existence, if present, record the distance difference between Hash[sum[i]] and I, otherwise hash[sum[i] = I. The maximum distance difference is obtained at the end of a single traversal, and the specific segment can be obtained.
Interviewer AngleSimilar topics are "and the largest Subarray", "and a subarray of 0", "and the nearest sub-array of 0". The common solution is through prefixes and sum[i].
Nine-chapter algorithm surface test questions 34 Maximum 01 substrings