Tow Sum With Id

Run Settings
LanguageC#
Language Version
Run Command
using System; using System.Collections.Generic; using System.Linq; class MainClass { static void Main() { int[] array = new int[5] {1,3,5,6,9}; bool retData = HasPairWithSum(array,8); Console.WriteLine(retData); } private static bool HasPairWithSum(int[] data, int sum) { int low= 0; int high = data.Length - 1; for(int i = high ; i >= 0 ; i--) { if(data[i] >= sum) { high = high - 1; } else { break; } } Console.WriteLine(high); while (low < high){ int s = sum - data[high]; if(data[low] == s) return true; low = high - 1; } return false; } }
Editor Settings
Theme
Key bindings
Full width
Lines