Skip to content

Latest commit

 

History

History
45 lines (35 loc) · 805 Bytes

File metadata and controls

45 lines (35 loc) · 805 Bytes

LTTS

Next Palindrome of Number

We are given an interger N and we have to return the next number whose digits form a palindrome.

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

bool isPalindrome(int n) {
  string s = to_string(n);
  string t = s;
  reverse(t.begin(), t.end());
  return t == s;
}

int getNextPalindrome(int N) {
  N++;
  while(true) {
    if(isPalindrome(N)) {
      return N;
    } else {
      N++;
    }
  }
}

int main() 
{
    int N = 121;
    int res = getNextPalindrome(N);
    cout << "res : " << res << "\n";
}
About Me
  • Full Stack Web Developer
  • Competitive Programmer

kiranpalsingh