Reverse Integer Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 time=272ms accepted public class Solution { public int reverse(int x) { long recv=0; int mod=0; int xabs=Math.abs(x); while(xabs>0){ mod=xabs%…
7.Reverse Integer Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note:Assume we are dealing with an environment which could only stor…
7. Reverse Integer 题目描述: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an environment which could o…
Problem: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 终于什么都没参考就一次Accept了.可能是这题比较简单,同时自己也进步了一点点,leetcode就是这样给我们增加信心的吧. 我是这样想的,利用除10和模10两个操作,将每个数字分离在vec中,然后相应的乘以10的倍数输出就行.如果这个数在-10与10之间直接返回就好. 代码如下: class S…
一天一道LeetCode系列 (一)题目 Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 (二)解题 这题看上去很简单,动笔一挥之下,写出如下代码: class Solution { public: int reverse(int x) { bool flag = false; if(x<0) { x=-k; flag = true; } long result…
这题简单,也花了我好长时间,我自己写的code比较麻烦,也没啥技巧:按正负性分类执行,先转化成字符串,用stringbuilder进行旋转,如果超出范围了就用try catch public int reverse(int x) { try { int result = 0; if (x == 0) { return x; } else if (x < 0) { String num = Integer.toString(0 - x); String newNum = new StringBui…