Created
March 23, 2015 22:29
-
-
Save JeremyMorgan/765cdd9af70c57134671 to your computer and use it in GitHub Desktop.
TwoSum in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
namespace TwoSum | |
{ | |
internal class Program | |
{ | |
public static Tuple<int, int> TwoSum(int[] numbers, int target) | |
{ | |
var lengthOfNumbers = numbers.Length; | |
Console.WriteLine("Length is " + lengthOfNumbers); | |
int indexValue1; | |
int indexValue2; | |
for (var counter = 0; counter < lengthOfNumbers; counter++) | |
{ | |
Console.WriteLine("Counter is " + counter); | |
if (numbers[counter] >= target) | |
{ | |
// go backwards | |
if (numbers[counter] > 0) | |
{ | |
Console.WriteLine(counter); | |
} | |
else | |
{ | |
Console.WriteLine("START"); | |
Console.WriteLine(counter); | |
} | |
} | |
//Console.WriteLine("Counter " + counter + " value is " + numbers[counter]); | |
} | |
// once we have our result: | |
var ourResult = new Tuple<int, int>(0, 0); | |
return ourResult; | |
} | |
private static void Main(string[] args) | |
{ | |
int[] ourNumbers = {2, 7, 11, 15}; | |
var ourTarget = 9; | |
var ourFinalResult = TwoSum(ourNumbers, ourTarget); | |
Console.WriteLine(ourFinalResult); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment