首页 > 学院 > 开发设计 > 正文

leetcode——9. Palindrome Number

2019-11-06 07:03:02
字体:
来源:转载
供稿:网友

题目:https://leetcode.com/PRoblems/palindrome-number/?tab=Description

题意:问一个数字串是不是回文串

只要分解它,然后从两边往前面比较即可。

class Solution {public:    bool isPalindrome(int x) {        if(x<0){            return false;        }        int c[100];        int i=0;        while(x){           c[i++]=x%10;           x=x/10;        }        bool flag=true;        for(int j=0;j<i;j++){            if(c[j]==c[i-j-1]){                            }else{                flag=false;            }        }        return flag;    }};


上一篇:18A - Triangle

下一篇:排序

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表