题目链接

动画解释

代码解释
- class Solution {
- public:
- int triangleNumber(vector<int>& nums)
- {
- sort(nums.begin(),nums.end());
- int cout = 0;
- int fix = nums.size()-1;
- while(fix>1)
- {
- int left = 0;
- int right = fix-1;
- while(left < right)
- {
- if(nums[left] + nums[right] > nums[fix])
- {
- cout += right-left;
- right--;
- }
- else
- {
- left++;
- }
- }
- fix--;
- }
- return cout;
- }
- };