Can we find Maximum subarray using partial sums?

Here's my Code. The time complexity is O(n) and no space is O(1) So,why don't we use this easy to implement solution ?

    int ans=arr[1],sum=0,min_sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=arr[i];
        ans=max(ans,sum-min_sum);
        min_sum=min(sum,min_sum);
    }
    cout<<ans<<endl;