[leetcode]_Reverse Integer】的更多相关文章

经历了三道树的题后,完全崩溃中,急需一道非树图的题来挽救信心. 题目:反转数字.input : 123 , output : 321. 思路:直接,没什么好说的. 自己代码:很龊,有大量的冗余信息,还申请了一个List,虽然AC了,但有很大改进空间. public int reverse(int x) { boolean negative = false; if(x < 0) { negative = true; x = x * (-1); } List<Integer> result…
最近在LeetCode上做题,写点东西记录一下,虽然自己做的都是些很水的题目,但是重在练手. 题号7:Reverse Integer,题目描述: Reverse digits of an integer:例如,输入123,输出321:输入-123,输出-321. 思路很简单:将原数的每一位求出,然后将原数的每一位倒序,生成一个整数.在程序中,使用了队列,利用其先进先出的原则,倒序原数每一位. 注意的地方:防止溢出. 代码如下: class Solution { public: int rever…
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before coding. Bonus points for you if you have already thought throu…
397. Integer Replacement QuestionEditorial Solution My Submissions   Total Accepted: 5878 Total Submissions: 21519 Difficulty: Easy Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If n is odd, you can…
https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to its english words representation. Given input is guaranteed to be less than 231 - 1. For example, 123 -> "One Hundred Twenty Three" 12345 -> "Tw…
https://leetcode.com/problems/integer-break/ Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example, given n = 2, return 1 (2…
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/integer-to-roman/Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999.===Comments by D…
第一天上课,数据库老师说对于计算机系的学生,凡是在课本上学到的专业知识都是过时的.深以为然,感觉大学两年半真的不知道学了什么,为未来感到担忧,C++也不敢说是精通,入门还差不多.最近丧的不行,不管怎么样,每天还是要进步一点点. 题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 感觉不难,写了才发现自己没考虑溢出的问题,为判断溢出折腾了好久,心好累,提…
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before coding. Bonus points for you if you have already thought throug…
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get. For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 +…