zoukankan      html  css  js  c++  java
  • 【leetcode】Reverse Integer

    题目描述:

    Reverse digits of an integer.

    Example1: x = 123, return 321
    Example2: x = -123, return -321

    很简单的题目其实用个数组就能解决了,不过用了一下queue,注意负数的情况。

     1 class Solution {
     2 public:
     3     int reverse(int x) {
     4         bool flg=false;
     5         if(x<0){
     6             flg=true;
     7             x=-x;
     8         }
     9         queue<int> a;
    10         while(x>0){
    11             a.push(x%10);
    12             x/=10;
    13         }
    14         x=0;
    15         while(!a.empty()){
    16             x=x*10;
    17             x+=a.front();
    18             a.pop();
    19         }
    20         return flg?-x:x;
    21     }
    22 };
  • 相关阅读:
    Ajax(三)
    Ajax(二)
    Django(四)
    Ajax(一)
    Django(三)
    Django(二)
    Django(一)
    Http协议
    Bootstrap
    python 绑定方法
  • 原文地址:https://www.cnblogs.com/MrLJC/p/3665666.html
Copyright © 2011-2022 走看看