485. Find the number of consecutive 1 in the binary string Max consecutive Ones

Source: Internet
Author: User


Given a binary array, find the maximum number of consecutive 1s in this array.

Example 1:

Input: [1,1,0,1,1,1] Output: 3Explanation: the first and digits or the last three digits is consecutive 1s.    The maximum number of consecutive 1s is 3.

note:

    • The input array would be only contain and 0 1 .
    • The length of input array is a positive integer and would not exceed 10,000

Find the number of consecutive 1 in a binary string.


  
 
  1. static public int FindMaxConsecutiveOnes(int[] nums) {
  2. if (nums.Length == 0) {
  3. return 0;
  4. }
  5. int maxNumber = 0;
  6. int number = 0;
  7. for ( int i = 0 I <= Nums length I ++) {
  8. if (i != nums.Length && nums[i] == 1) {
  9. number++;
  10. } else {
  11. if (number > maxNumber) {
  12. maxNumber = number;
  13. }
  14. number = 0;
  15. }
  16. }
  17. return maxNumber;
  18. }



From for notes (Wiz)

485. Find the number of consecutive 1 in the binary string Max consecutive Ones

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.