-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
33 lines (32 loc) · 808 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
namespace _3SumSmaller
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
static int ThreeSumSmaller(int[] nums, int target)
{
Array.Sort(nums);
int res = 0;
for (int i = 0; i < nums.Length - 2; i++)
{
int sum = target - nums[i];
int li = i + 1, hi = nums.Length - 1;
while (li < hi)
{
if (nums[li] + nums[hi] < sum)
{
res += hi - li;
li++;
}
else
hi--;
}
}
return res;
}
}
}