concise c code


  • 0
    B
    int triangleNumber(int* nums, int numsSize) {
    	int i1, i2, i3, total;
    	
    	qsort(nums, numsSize, sizeof(int), comp);
    	for (total = i1 = 0; i1 < numsSize - 2; i1++)
    		for (i2 = i1 + 1, i3 = i2 + 1; i2 < numsSize - 1; i2++) {
    			if (i3 <= i2)
    				i3 = i2 + 1;
    			for (; i3 < numsSize && nums[i1] + nums[i2] > nums[i3]; i3++);
    			total += (i3 - i2 - 1);
    		}
    	return total;
    }
    

Log in to reply
 

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