We only need to satisfy the condition that the sum of the two shorter edges is strictly greater than the longest edge.

```
public int triangleNumber(int[] nums) {
int n = nums.length;
if (n < 3) return 0;
Arrays.sort(nums);
int ans = 0;
for (int i = 0; i < nums.length-2; i++) {
for (int j = i+1, k = i+2; k < nums.length; k++) {
while (j < k && nums[i]+nums[j] <= nums[k]) j++;
ans += k-j;
}
}
return ans;
}
```