fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. using namespace std;
  4.  
  5. bool is_palindrome(vector<int> arr, int l , int r ) {
  6. if (l >= r) return true;
  7. if (arr[l] != arr[r]) return false;
  8. return is_palindrome(arr, l + 1, r - 1);
  9. }
  10. void solve() {
  11. vector<int> arr = {1, 2,3,2,1};
  12. cout << is_palindrome(arr,0,arr.size()-1) << endl;
  13. vector<int> arr2 = {1,2,3,1};
  14. cout << is_palindrome(arr2,0,arr2.size()-1) << endl;
  15. vector<int> arr3 = {1,2,2,1};
  16. cout << is_palindrome(arr3,0,arr3.size()-1) << endl;
  17. }
  18.  
  19. int main() {
  20. IOS;
  21. solve();
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
1
0
1