【LeetCode】9. Palindrome Number

题目:

Determine whether an integer is a palindrome. Do this without extra space.

思考过程:

题目很简单,要求是判断一个数是否是回文数,回文数的定义就是数字翻转之后与原先的数一样的话就是回文数,比如 101 , 22, 1 等,所以要处理这个问题的话,只需要将一个数的最高位换到最低位,次高位换到第二低位,依次全部换好之后,得到一个新的数,判断新的数是否与原先的数相等,如果相等,就是回文数,如果不等,就不是,所以解答代码如下:

//c++
class Solution {
public:
    bool isPalindrome(int x) {
        int r=0,xc=x;
        while(xc>0)
        {
            r*=10;
            r+=xc%10;
            xc/=10;
        }
        return r==x;
    }
};
时间: 2024-08-02 00:30:46

【LeetCode】9. Palindrome Number的相关文章

【Oracle】ORA-23421: job number XXXX is not a job in the job queue

 检查一个数据库的alert日志时,查看一些job报错,由于是自己的测试库,考虑把job停止掉.但是遇到如下错误: sys@im1>exec DBMS_JOB.broken(275,true); BEGIN DBMS_JOB.broken(275,true); END; * ERROR at line 1: ORA-23421: job number 275 is not a job in the job queue ORA-06512: at "SYS.DBMS_SYS_ERROR&qu

[LeetCode]125.Valid Palindrome

[题目] Valid Palindrome  Total Accepted: 3479 Total Submissions: 16532My Submissions Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Panama" is a pa

[LeetCode]9.Palindrome Number

[题目] Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of usin

LeetCode总结【转】

转自:http://blog.csdn.net/lanxu_yy/article/details/17848219 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近完成了www.leetcode.com的online judge中151道算法题目.除各个题目有特殊巧妙的解法以外,大部分题目都是经典的算法或者数据结构,因此做了如下小结,具体的解题思路可以搜索我的博客:LeetCode题解 题目 算法 数据结构 注意事项 Clone Graph BFS 哈希表 Word Ladder II

嗨 甲骨文【1】

[序]为了在工作中写存储过程,.同时,我准备写学习<精通Oracle 10g PL/SQL编程>(水利水电)一书的学习笔记. 这些你能不能写全:Data Query Language--SELECTData Manipulation Language--INSERT,UPDATE,DELETETransactional Control Language--COMMIT,ROLLBACK,SAVEPOINTData Definition Language--CREATE TABLE,ALTER

【MySQL】再说MySQL中的 table_id

[背景] 最近线上一个实例出现了主从数据不一致的情况,也即从库丢失数据的情况.根本原因:"由于table_list->table_id为uint,而m_table_id为ulong,主库上assign的table map id 总是一直递增的 当超过2^32后,备库出现溢出,导致row模式下备库对应table id的事件全部丢失,产生主备不一致." [问题分析]一 table_id 介绍     当MySQL 开启日志模式时,binlog会记录所有对数据库的变更操作.binlog

【原创】各种 JSON 解析库的功能简介

这里增加一项无聊的对比图,看客自斟. =================================== [rui_maciel/mjson]Last Update:2013-05-15(最新版本为 mjson-1.5 发布日期为 2012-08-22)description M's JSON parser is a small JSON parser written in ISO C which enables the user to handle information describe

【原创】RabbitMQ官网文档翻译 -- Highly Available Queues

      为了方便工作中使用,对 RabbitMQ 的[高可用]相关文档进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨.此文以中英对照方式呈现. 官方原文:http://www.rabbitmq.com/ha.html ============== 我是分割线 =============== Highly Available Queues高可用 queue If your RabbitMQ broker consists of a single node, then

【Solidity】8. 杂项 - 深入理解Solidity

索引 [Solidity]1.一个Solidity源文件的布局 [Solidity]2.合约的结构体 [Solidity]3.类型 [Solidity]4.单位和全局可变量 [Solidity]5.表达式和控制结构 [Solidity]6. 合约 [Solidity]7. 部件 [Solidity]8. 杂项 杂项 存储中状态变量的布局 静态大小变量(除映射和动态大小的数组类型的所有内容)在存储连续布置从需要小于32个字节被打包成一个单一的存储槽是否可能位置0多个项目开始,根据下面的规则: 存储