public class Solution {

public int singleNonDuplicate(int[] nums) {

int index = 0;

if (nums[0] != nums[0+1]) {

index = 0;

}

if (nums[nums.length-1] != nums[nums.length-2]){

index = nums.length - 1;

}

for (int i = 1; i < nums.length-1; i++) {

if (nums[i] != nums[i+1] && nums[i] != nums[i-1]) {

index = i;

}

}

return nums[index];

}

}