A problem about "485. Max Consecutive Ones"


  • 0
    B

    This is my code.

    class Solution {
    public:
     int findMaxConsecutiveOnes(vector<int>& nums) {
      int record=0,sign=0;
      for(int i=0; i<nums.size(); ++i)
      {
        if(nums[i]==1)
         record++;
        if((nums[i]==0||i==nums.size()-1)&&record>sign)
        {
          sign=record;
          record=0;
        }
      }
      return sign;
     }
    };

    Input:
    [1,1,1,1,1,1,1,1, .......,1]
    Output:
    3323
    Expected:
    2840
    what's wrong with my program?


  • 0

    @beihunshenlu said in A problem about "485. Max Consecutive Ones":

    what's wrong with my program?

    For starters, it's not formatted. (Which means people are less likely to read it and help you.)


  • 0
    B

    Ok, thanks for replying. I will be more careful at next time.


  • 0

    And now it can't be tested. I get a compile error saying "Line 3: stray '\343' in program". Seems like you really don't want help.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.