Why TLE? I got TLE for very large test case.


  • 0
    M
    public int maxSubArray(int[] nums) {
            int len =nums.length;
            int sum=nums[0];
            int tempsum=nums[0];
            if(len==1){
                return sum;
            }
            for(int i=1;i<len;i++){
                if(tempsum>0){
                    tempsum+=nums[i];
                }
                else{
                    tempsum=nums[i];
                }
                sum=Math.max(sum,tempsum);
            }
            return sum;
        }

Log in to reply
 

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