摘要:題目鏈接題目分析給定一個(gè)二進(jìn)制數(shù)組只含有和的數(shù)組,返回最長(zhǎng)的串。思路逐個(gè)遍歷,若為則計(jì)數(shù)。遇到則判斷當(dāng)前計(jì)數(shù)是否大于之前記錄的最大數(shù)字,并置零。最終代碼若覺(jué)得本文章對(duì)你有用,歡迎用愛(ài)發(fā)電資助。
D67 485. Max Consecutive Ones 題目鏈接
485. Max Consecutive Ones
題目分析給定一個(gè)二進(jìn)制數(shù)組(只含有0和1的數(shù)組),返回最長(zhǎng)的1串。
思路逐個(gè)遍歷,若為1則計(jì)數(shù)。遇到0則判斷當(dāng)前計(jì)數(shù)是否大于之前記錄的最大數(shù)字,并置零。
返回最大數(shù)。
最終代碼$max){ $max = $current; } } else{ $current = 0; } } return $max; } }
若覺(jué)得本文章對(duì)你有用,歡迎用愛(ài)發(fā)電資助。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/31539.html
摘要:示例輸入輸出解釋開(kāi)頭的兩位和最后的三位都是連續(xù),所以最大連續(xù)的個(gè)數(shù)是注意輸入的數(shù)組只包含和。輸入數(shù)組的長(zhǎng)度是正整數(shù),且不超過(guò)。 公眾號(hào):愛(ài)寫bug 給定一個(gè)二進(jìn)制數(shù)組, 計(jì)算其中最大連續(xù)1的個(gè)數(shù)。 Given a binary array, find the maximum number of consecutive 1s in this array. 示例 1: 輸入: [1,1,0...
摘要:示例輸入輸出解釋開(kāi)頭的兩位和最后的三位都是連續(xù),所以最大連續(xù)的個(gè)數(shù)是注意輸入的數(shù)組只包含和。輸入數(shù)組的長(zhǎng)度是正整數(shù),且不超過(guò)。 公眾號(hào):愛(ài)寫bug 給定一個(gè)二進(jìn)制數(shù)組, 計(jì)算其中最大連續(xù)1的個(gè)數(shù)。 Given a binary array, find the maximum number of consecutive 1s in this array. 示例 1: 輸入: [1,1,0...
摘要:示例輸入輸出解釋開(kāi)頭的兩位和最后的三位都是連續(xù),所以最大連續(xù)的個(gè)數(shù)是注意輸入的數(shù)組只包含和。輸入數(shù)組的長(zhǎng)度是正整數(shù),且不超過(guò)。 公眾號(hào):愛(ài)寫bug 給定一個(gè)二進(jìn)制數(shù)組, 計(jì)算其中最大連續(xù)1的個(gè)數(shù)。 Given a binary array, find the maximum number of consecutive 1s in this array. 示例 1: 輸入: [1,1,0...
Problem Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at most one 0. Example 1:Input: [1,0,1,1,0]Output: 4Explanation: Flip the first zero will get the ...
Max Consecutive Ones 題目鏈接:https://leetcode.com/problems... public class Solution { public int findMaxConsecutiveOnes(int[] nums) { // loop invariant: // global is the max so far, ...
閱讀 3214·2021-10-12 10:20
閱讀 2926·2021-09-27 13:56
閱讀 898·2021-09-27 13:36
閱讀 1501·2021-09-26 09:46
閱讀 2504·2019-08-30 14:02
閱讀 2751·2019-08-28 18:14
閱讀 1336·2019-08-26 10:32
閱讀 1780·2019-08-23 18:25