zoukankan      html  css  js  c++  java
  • Reverse Integer

    Reverse Integer

    Reverse digits of an integer.

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

     1 public class Solution {
     2     public int reverse(int x) {
     3         int result = 0;
     4         boolean flag_neg = false;
     5         if(x < 0){
     6             flag_neg = true;
     7             x = -x;
     8         }
     9         while(x != 0){
    10             int temp = x % 10;
    11             result = result * 10 + temp;
    12             x /= 10;
    13         }
    14         if(flag_neg)
    15             result = -result;
    16         return result;
    17     
    18     }
    19 }
  • 相关阅读:
    class线程信息
    Class 文件简介
    JVM对象及垃圾回收处理
    jvm体系结构
    查找

    二叉树
    队列


  • 原文地址:https://www.cnblogs.com/luckygxf/p/4085921.html
Copyright © 2011-2022 走看看