码迷,mamicode.com
首页 > Windows程序 > 详细

Leetcode 9 Palindrome Number C#

时间:2016-08-24 06:41:03      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:

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

 

Solution:

 public bool IsPalindrome(int x) {
        if(x<0) return false;
        if(x == 0 || x/10 ==0) return true;
        int y = 0;
        int sentinel = x;
        while(x>0 )
        {
            y =y*10 + x%10;
            x = x/10;
           
        }
        return sentinel==y ;
    }

 

Leetcode 9 Palindrome Number C#

标签:

原文地址:http://www.cnblogs.com/renyualbert/p/5801433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!