题目:

分析:
思想:
代码:
- class Solution {
- public int triangleNumber(int[] nums) {
- Arrays.sort(nums);
- int n = 0;
- int c = nums.length - 1;
- while (c >= 2) {
- int left = 0;
- int right = c - 1;
- while (left < right) {
- if (nums[left] + nums[right] > nums[c]) {
- n += (right - left);
- right--;
- } else {
- left++;
- }
- }
- c--;
- }
- return n;
-
- }
- }