// 第一题,用差序列做,希望有dl指正 bool isSymmetric(vector<int> &diff, int begin, int end) { for(int i = begin; i < (begin + end)/2; i++) { if(diff[i] != diff[begin + end - i]) { return false; } } return true; } int solution(vector<int>& A) { int n = A.size(); vector<int> diff(n-1, 0); for(int i = 0; i < n-1; i++) { diff[i] = A[i+1] - A[i]; } int ret = A[0]; for(int i = 0; i < (n-1)/2; i++) { if(diff[i] != diff[n-2-i]) { if(i == 0 && isSymmetric(diff, 1, n-2) || isSymmetric(diff, 0, n-3)) { if(isSymmetric(diff, 1, n-2)) { ret = A[n-1] + diff[0]; } else if(isSymmetric(diff, 0, n-3)) { ret = A[0] - diff[n-2]; } } else { if(diff[i] > diff[n-2-i]) { ret = A[i] + diff[i+1]; } else { ret = A[n-1-i] - diff[i]; } } break; } } return ret; }