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 };
  • 相关阅读:
    对学生排序 Exercise07_17
    消除重复 Exercise07_15
    计算gcd Exercise07_14
    随机数选择器 Exercise07_13
    dom4j 学习总结
    jQuery学习总结(二)
    jQuery学习总结(一)
    SQL中Where与Having的区别
    html + css (1)
    struts2+json
  • 原文地址:https://www.cnblogs.com/gousheng/p/7639634.html
Copyright © 2011-2022 走看看