using System.Collections;
using System.Collections.Generic;
public static void Main()
int[] nums = {-1,0,1,-1,2,-4};
IList<IList<int>> list = ThreeSum(nums);
public static IList<IList<int>> ThreeSum(int[] nums) {
IList<IList<int>> sets = new List<IList<int>>();
Hashtable solutions = new Hashtable();
if (nums[0] == 0 && nums[0] == nums[nums.Length - 1]) {
sets.Add(new List<int> {nums[0], nums[0], nums[0]});
while (i < nums.Length - 2)
int target = 0 - nums[i];
Dictionary<int, int> dict = new Dictionary<int, int>();
for (int j = i + 1; j < nums.Length; j++)
if (dict.TryGetValue(nums[j], out val)) {
List<int> list = new List<int> {nums[i], val, nums[j]};
string key = string.Concat(list);
if (!solutions.ContainsKey(key)) {
solutions.Add(key, null);
else if (!dict.TryGetValue(target-nums[j], out val))
dict.Add(target-nums[j], nums[j]);
while (i < nums.Length && nums[i] == curr)
public static void PrintList(IList<int> list)
StringBuilder sb = new StringBuilder();
Console.Write("[{0}]\n", sb);