Skip to content

Instantly share code, notes, and snippets.

@mofodox
Last active December 17, 2015 12:09
Show Gist options
  • Save mofodox/5607251 to your computer and use it in GitHub Desktop.
Save mofodox/5607251 to your computer and use it in GitHub Desktop.
My attempt on getting equilibrium index in an array
function sol(A) {
var eia = A.length,
addLeft = 0,
addRight = 0;
for(var i=0; i<eia; i++) {
addRight += A[i]
}
for(var i=0; i<eia; i++) {
addRight -= A[i];
if(addRight == addLeft) {
return i;
}
addLeft += A[i];
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment