Leetcode 525. Contiguous Array

Input: nums = [0,1]
Output: 2
Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1.
Input: nums = [0,1,0]
Output: 2
Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1.
  • 1 <= nums.length <= 105
  • nums[i] is either 0 or 1.
  1. I was think using sliding window in this question, and hashmap would be good to notice current total sum.
  2. if we found another number with the same sum, which mean they have the same 0 and 1 between them. calculate the different between these two number

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store