Skip to content

Instantly share code, notes, and snippets.

@jamie23
Created March 8, 2014 00:02
Show Gist options
  • Save jamie23/9422825 to your computer and use it in GitHub Desktop.
Save jamie23/9422825 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Solution {
public static void main(String[] args){
Solution x = new Solution();
int[] A = {-7,1,5,2,-4,3,0};
System.out.println(x.solution(A));
}
public int solution(int[] A) {
// write your code in Java SE 7
if(A.length==0){
return -1;
}
for(int i=0;i<A.length;i++){
int side1 = 0;
int side2 = 0;
//Run through each side getting a total
//First side
for(int j=0;j<i;j++){
side1+=A[j];
}
//Second side
if(i!=A.length){
for(int l=i+1;l<A.length;l++){
side2+=A[l];
}
}
if(i==A.length){
if(A[A.length]==side1){
System.out.println("WINNER: " + i);
//return i;
}
}
if(side1==side2){
System.out.println("WINNER: " + i);
//return i;
}
System.out.println(side1 + "\n" + side2 + "\n");
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment