<2017年6月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

  • 随笔 - 57
  • 文章 - 7
  • 评论 - 0
  • 引用 - 0

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

Blog

Coder 必备技巧

Compiler for Wurq

搜索

  •  

最新评论

阅读排行榜

评论排行榜

【LeeCode 2017/06/21】7. Reverse Integer
 1 class Solution {
 2 public:
 3     int reverse(int x) {
 4         list<long long>num;
 5         bool mark = false;
 6         if (x < 0){
 7             mark = true;
 8             x = -x;
 9         }
10 
11         while (x){
12             num.push_back(x % 10);
13             x = x / 10;
14         }
15 
16         long long sum = 0;
17         while (!num.empty()) {
18             sum = sum*10+num.front();
19             num.pop_front();
20         }
21 
22         if (mark)
23             sum = -sum;
24 
25         int ans = sum;
26 
27         if (sum > 0X7fffffff  || sum < -0X7fffffff-1)
28             ans = 0;
29 
30         return ans;
31     }
32 };

posted on 2017-06-21 09:51 Wurq 阅读(65) 评论(0)  编辑 收藏 引用 所属分类: 【LeeCode 每日N题】


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理