My question, maybe this is leetcode system bug?


  • 0

    My cpp code is:

    class Solution {
    public:
      int maxSubArray(vector<int>& nums) {
        int ret;
    
        int sum = 0;
        for (int i = 0; i < nums.size(); i ++)
        {
          sum += nums[i];
    
          ret = max(ret, sum);
          sum = max(sum, 0);
        }
    
        return ret;
      }
    };
    

    What makes me puzzle is that a case input is: [-2, 1, -3, 4, -1, 2, 1, -5, 4], If I use my local g++ environment and leetcode platform Custom Testcase, the result is always 6, when I submit my solution, the result is always 10...
    @administrators @contributors @StefanPochmann would you please check it?


Log in to reply
 

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