Why am I getting wrong answer for input:[1] on OJ ,it's working fine on my local machine... my code is..


  • 0
    D

    class Solution {
    public:
    int rob(vector<int>& nums) {
    unsigned m1=0,m2=0;
    unsigned j=1,i=0;
    while(i<=nums.size() && j<=nums.size()){
    m1=max(m1+nums[i],m1);
    m2=max(m2+nums[j],m2);
    i+=2;j+=2;
    }
    return max(m1,m2);
    }
    };


Log in to reply
 

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