由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问一个reverse int的问题
相关主题
求助各位大牛:LeetCode的Decode Waysleetcode里, backtracking的time complexity怎么算,比如permutations这题目
请教一道Leetcode 题, 多谢八皇后位运算的问题
leetcode 一道题 valid palindrome3sum on LeetCode OJ
关于leetcode上那个买卖股票II的问题这段代码在leetcode上面跑不了??
leetcode上的populate next node I and IIleetcode很有意思啊
Best Time to Buy and Sell Stock II这么简单?leetcode我这2个palindrome的为什么过不了大oj
leetcode 3sum请大牛解释一下leetcode新题
请教下leetcode Permutations IIlc 上面4 sum的时间复杂度要求多少?
相关话题的讨论汇总
话题: int话题: overflow话题: temp话题: sign话题: solution
进入JobHunting版参与讨论
1 (共1页)
g***j
发帖数: 1275
1
请问leetcode上面的oj,没有考虑overflow么?但是题目描述里面提到了overflow
显然我这个code没有处理overflow啊,但是两个都过了,如果要考虑overflow,怎么处
理呢?
class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x == 0) return x;

int sign = 1;

if (x < 0) { sign = -1; x = -x;}

int temp = 0;


while(x > 0) {

temp = temp * 10 + x %10;

x = x/10;

}

return temp*sign;
}
};
p*****2
发帖数: 21240
2

overflow跟面试官提一下就可以了吧。让他直到你考虑到这种情况了。其实一般面试没
有leetcode上要求那么苛刻。

【在 g***j 的大作中提到】
: 请问leetcode上面的oj,没有考虑overflow么?但是题目描述里面提到了overflow
: 显然我这个code没有处理overflow啊,但是两个都过了,如果要考虑overflow,怎么处
: 理呢?
: class Solution {
: public:
: int reverse(int x) {
: // Start typing your C/C++ solution below
: // DO NOT write int main() function
: if(x == 0) return x;
:

1 (共1页)
进入JobHunting版参与讨论
相关主题
lc 上面4 sum的时间复杂度要求多少?leetcode上的populate next node I and II
在leetcode上通不过 在自己电脑上可以运行 请大牛指教Best Time to Buy and Sell Stock II这么简单?
请教leetcode一道题leetcode 3sum
请教一个leetcode OJ问题请教下leetcode Permutations II
求助各位大牛:LeetCode的Decode Waysleetcode里, backtracking的time complexity怎么算,比如permutations这题目
请教一道Leetcode 题, 多谢八皇后位运算的问题
leetcode 一道题 valid palindrome3sum on LeetCode OJ
关于leetcode上那个买卖股票II的问题这段代码在leetcode上面跑不了??
相关话题的讨论汇总
话题: int话题: overflow话题: temp话题: sign话题: solution