diff --git a/problem1.cs b/problem1.cs new file mode 100644 index 00000000..e3420586 --- /dev/null +++ b/problem1.cs @@ -0,0 +1,23 @@ +public class Solution { + public IList> Generate(int numRows) { + IList> output = new List>(); + for(var i=0;i(); + for(var j=0;j<=i;j++) + { + if(j==0||j==i) + { + innerList.Add(1); + } + else + { + innerList.Add(output[i-1][j-1]+output[i-1][j]); + } + } + output.Add(innerList); + + } + return output; + } +} \ No newline at end of file diff --git a/problem2.cs b/problem2.cs new file mode 100644 index 00000000..cf87e631 --- /dev/null +++ b/problem2.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +public class Solution +{ + public int FindPairs(int[] nums, int k) + { + var map = new Dictionary(); + var result = new HashSet(); + + for (int i = 0; i < nums.Length; i++) + { + map[nums[i]] = i; + } + + for (int i = 0; i < nums.Length; i++) + { + int complement = nums[i] - k; + if (map.ContainsKey(complement) && map[complement] != i) + { + var pair = new int[] { nums[i], complement }; + Array.Sort(pair); + result.Add($"{pair[0]},{pair[1]}"); + } + + complement = nums[i] + k; + if (map.ContainsKey(complement) && map[complement] != i) + { + var pair = new int[] { nums[i], complement }; + Array.Sort(pair); + result.Add($"{pair[0]},{pair[1]}"); + } + } + + return result.Count; + } +}