7. Reverse Integer

    xiaoxiao2021-03-25  171

    Reverse digits of an integer.

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

    public class Solution { public int reverse(int x) { int flag=x>0?1:-1; x*=flag; long re=0; while(x>0){ re=re*10+x; x/=10; } if(re>Integer.MAX_VALUE) return 0; return (int)re*flag; } }

    转载请注明原文地址: https://ju.6miu.com/read-2951.html

    最新回复(0)