Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created February 24, 2017 22:50
Show Gist options
  • Save hikilaka/426b43d0fbeff52141055e29a771897c to your computer and use it in GitHub Desktop.
Save hikilaka/426b43d0fbeff52141055e29a771897c to your computer and use it in GitHub Desktop.
bool isSmooth(std::vector<int> arr) {
auto first = std::begin(arr);
auto last = std::rbegin(arr);
if (*first == *last) {
if ((arr.size() % 2) == 0) {
std::advance(first, arr.size() / 2);
auto next = std::prev(first);
return (*first + *next) == *last;
} else {
std::advance(first, arr.size() / 2);
return *first == *last;
}
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment