Skip to content

Commit 60a1af2

Browse files
authored
Create Solution.java
1 parent 5160004 commit 60a1af2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public int triangleNumber(int[] nums) {
3+
Arrays.sort(nums);
4+
int n = nums.length;
5+
int res = 0;
6+
for (int i = n - 1; i >= 2; --i) {
7+
int l = 0, r = i - 1;
8+
while (l < r) {
9+
if (nums[l] + nums[r] > nums[i]) {
10+
res += r - l;
11+
--r;
12+
} else {
13+
++l;
14+
}
15+
}
16+
}
17+
return res;
18+
}
19+
}

0 commit comments

Comments
 (0)