@@ -0,0 +1,854 @@
+/**%0A * Main Points: %0A Assume a is the longest edge, b and c are shorter ones, to form a triangle, %0A they need to satisfy len(b) + len(c) %3E len(a)%0A this problem can be solved by 3 pointers, like 3 sum%0A * Time Complexity: O(n%5E2)%0A * Space Complexity: O(1)%0A**/%0Aclass Solution %7B%0A    public int triangleNumber(int%5B%5D nums) %7B%0A        if (nums == null %7C%7C nums.length %3C 3) return -1;%0A        int count = 0;%0A        for (int i = 2; i %3C nums.length; i++) %7B%0A            int left = 0, right = i - 1;%0A            while (left %3C right) %7B%0A                if (nums%5Bleft%5D + nums%5Bright%5D %3E nums%5Bi%5D) %7B%0A                    count += right - left; // because if we fix i, fix right, left can be all from original left to right%0A                    right--;%0A                %7D else %7B%0A                    left++;%0A                %7D%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A%7D

like 3 sum