zoukankan      html  css  js  c++  java
  • lintcode491 回文数

    回文数 

    判断一个正整数是不是回文数。

    回文数的定义是,将这个数反转之后,得到的数仍然是同一个数。

     注意事项

    给的数一定保证是32位正整数,但是反转之后的数就未必了。

    样例

    11121112321 这些是回文数。

    23321232 这些不是回文数。

    代码

     1 class Solution {
     2 public:
     3     /*
     4      * @param num: a positive number
     5      * @return: true if it's a palindrome or false
     6      */
     7     bool isPalindrome(int num) {
     8         // write your code here
     9         if (num < 0) {
    10             return false;
    11         }
    12         vector<int> res;
    13         vector<int> com_res;
    14         int temp;
    15         while (num) {
    16             temp = num % 10;
    17             res.push_back(temp);
    18             num = num / 10;
    19         }
    20         com_res = res;
    21         reverse(res.begin(), res.end());
    22         if (res == com_res) {
    23             return true;
    24         }
    25         return false;
    26         
    27     }
    28 };
  • 相关阅读:
    Date计算人活了多少天
    微信红包平均分法
    math practise
    Array sort
    static memory management
    java数组中的选择排序
    java数组中的冒泡排序
    数组联系2 模拟酒店系统
    数组练习1(模拟栈)
    二维数组
  • 原文地址:https://www.cnblogs.com/gousheng/p/7639634.html
Copyright © 2011-2022 走看看