Reverse Integer Leetcode Python Java
2016-06-28 08:08
609 查看
Reverse Integer
Total Accepted:147726 Total Submissions:
622694 Difficulty: Easy
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Python:
#coding:utf-8
class Solution:
def reverseInteger(self,x):
tmp=0
while x!=0:
4000
tail=x%10
newresult=result*10+tail
if (newresult-tail)/10!=rsult:
return 0
result=newresult
x=x/10
return x
Java:
pulic class Solution:
public int reverse(int x):
long result=0;
while(x!=0){
int tail=x%10;
int newresult=result*10+tail;
if(newresult>INT_MAX||newreault<INT_MIN){
return 0;
}
result=newresult;
x=x/10;
}
return result;
相关文章推荐
- python学习笔记之面向对象、基本I/O操作(一)
- [Python爬虫笔记][随意找个博客入门(一)]
- python包使用指南-创建虚拟环境
- python类库
- python中的oop面向对象基本编程(类、实例、魔术)
- python setup
- Python log code
- python dict遍历
- Python+Django+Eclipse 在Windows下快速开发自己的网站
- python学习总结 常见问题
- python中的变量,运算符
- python学习总结 基本操作
- python安装与使用
- 初识 Python
- Python基础知识学习笔记(1)
- 对Python中文分词模块结巴分词算法过程的理解和分析
- Python 文件操作
- Python 之 多线程同步(1)
- python 百度cpc点击
- 执行Python出现LookupError: unknown encoding: cp65001解决办法