Created
October 27, 2017 14:55
-
-
Save jpolvora/a2164c4e00dc7d3290337d30c5770999 to your computer and use it in GitHub Desktop.
This file contains 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
int arrayMaximalAdjacentDifference(int[] inputArray) { | |
var major = 0; | |
for (int i = 0; i < inputArray.Length; i++) { | |
var previous = i - 1; | |
var next = i + 1; | |
if (previous < 0 || next > inputArray.Length -1) continue; | |
var current = inputArray[i]; | |
var preval = inputArray[previous]; | |
var nextval = inputArray[next]; | |
int t1 = 0; | |
if (current >= preval) { | |
t1 = current - preval; | |
} else { | |
t1 = preval - current; | |
} | |
if (t1 >= major) major = t1; | |
if (current >= nextval) { | |
t1 = current - nextval; | |
} else { | |
t1 = nextval - current; | |
} | |
if (t1 >= major) major = t1; | |
} | |
return major; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment