DEV Community

Mujahida Joynab
Mujahida Joynab

Posted on

Is The List Palindrome?

`#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    list<int> lst;
    int val;
    while (cin >> val && val != -1)
    {
        lst.push_back(val);
    }
    int f = 0;
    for (int i = lst.front(), j = lst.back(); i < j; i++, j--)
    {
        if (i != j)
        {
            f = 1;
            break;
        }
    }
    if (f)
    {
        cout << "NO\n";
    }
    else
        cout << "YES\n";
}`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Retry later