[LeetCode] 485. Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
Note:
- The input array will only contain
0
and1
. - The length of input array is a positive integer and will not exceed 10,000
Subscribe to see which companies asked this question
很常見的題目類型 給一個字串(array, 數字) 找連續的元素. 不要看這種題型看似簡單
外面經常考變化題 或是 連續應用題
比如說 給你一個字串 "jjhhhhgsdjgjhsgSWQRgajn554avbnvbnvanb6545svdnbsvan2346456"
1) 先印出 j: 2 h: 4 format
2) 在統計有多少個元素 出現超過3次以上 ?
3) 連續出現最多次的是哪個元素 最少的又是哪些 ?
4) 如果區分大小寫呢?
留言
張貼留言