Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.
Note: The length of the given binary array will not exceed 50,000.
給予一個二元陣列,找到最大長度的子陣列,其包含的0和1數量相同。
提示:給予的二元陣列最長不超過50000。
0
就減一,遇到1
就加一。O(n^2)
,吃到TLE。0
和1
是一樣多的!O(n)
new
新增陣列取代掉vector
等結構,以縮短allocate的時間。LeetCode
C++