LeetCode:Palindrome Number

基本思路:把 int 转换成string  借用stringstream  时间复杂度O(n)

  

 1 class Solution {
 2 public:
 3    public:
 4     bool isPalindrome(int x) {
 5 
 6        stringstream ss;
 7        ss<<x;
 8        string str=ss.str();
 9        int sfront = 0;
10        int sback=str.length()-1;
11         while(sfront<sback)
12         {
13          if(str[sfront]!=str[sback])
14             return false;
15          ++sfront;
16          --sback;
17         }
18         return true;
19     }
20 };

 

posted @ 2015-06-03 21:46  尾巴草  阅读(97)  评论(0编辑  收藏  举报