标签:http alt lse int vector 代码 turn style info
1、题目描述
2、问题分析
暴力计算
3、代码
1 int triangleNumber(vector<int>& nums) { 2 int res =0; 3 if( nums.size() < 3) 4 return res; 5 6 for( int i = 0; i < nums.size() -2; i++){ 7 for( int j = i+1; j < nums.size()-1; j++){ 8 for( int k = j +1; k < nums.size(); k++){ 9 if( isTri(nums[i], nums[j], nums[k]) ) 10 res ++; 11 } 12 } 13 } 14 15 return res; 16 17 } 18 19 bool isTri(int a ,int b, int c){ 20 if( a+b<=c || b+c <= a || a+c<=b || a <=0 ||b <=0 ||c <=0 ) 21 return false; 22 else 23 return true; 24 }
LeetCode题解之Valid Triangle Number
标签:http alt lse int vector 代码 turn style info
原文地址:https://www.cnblogs.com/wangxiaoyong/p/9577122.html