Passed 11/13 cases, what is wrong with my code?


  • 0
    F

    Could anyone help to look at my code?
    It passed 11/13 cases.
    what is wrong with it?
    Thank you so much.

       class Solution {
        public:
            int minSubArrayLen(int s, vector<int>& nums) {
                sort(nums.begin(),nums.end());
                int size = nums.size();
        		int sum = 0;
        		int count = 0;
        		for(int i = size-1; i >= 0; i--)
        		{
        			sum = sum + nums[i];
        			count++;
        			if(sum >= s) break;
        		}
        		if(count == size) return 0;
        		else
        			return count;
            }
        };

  • 1
    I

    You shouldn't sort, the subArray means concatenated subarray the problem is not clear about that.


Log in to reply
 

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