由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 请教leetcode一道题
相关主题
请教一道Leetcode 题, 多谢问一个reverse int的问题
请问如何安全地reverse 一个integer一道关于两倍年龄的题目 (转载)
reverse an integer 怎么判断是否 overflow 来着有好的merge有序数组算法么
问个简单的atoi的问题帮忙看看我写的atoi有没有bug, 谢谢
请教一个reverse decimal number的问题什么也不管了,给了一个烙印很差的feedback
问个简单C reverse intDivide Two Integers
如何判断一个数是不是回文?问一道leetcode的题
请假大家一个问题求教一个, Leetcode 题.
相关话题的讨论汇总
话题: integer话题: parameter话题: extra话题: reverse话题: return
进入JobHunting版参与讨论
1 (共1页)
f*********m
发帖数: 726
1
题目如下。
我的问题:
如何理解提示中的最后一句话:“ You would then have to re-design the function
(ie, add an extra parameter).”加什么样的extra parameter?
谢谢。
题目:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if
you have already thought through this!
If the integer's last digit is 0, what should the output be? ie, cases such
as 10, 100.
Did you notice that the reversed integer might overflow? Assume the input is
a 32-bit integer, then the reverse of 1000000003 overflows. How should you
handle such cases?
Throw an exception? Good, but what if throwing an exception is not an option
? You would then have to re-design the function (ie, add an extra parameter).
f*********m
发帖数: 726
2
顶。

function

【在 f*********m 的大作中提到】
: 题目如下。
: 我的问题:
: 如何理解提示中的最后一句话:“ You would then have to re-design the function
: (ie, add an extra parameter).”加什么样的extra parameter?
: 谢谢。
: 题目:
: Reverse digits of an integer.
: Example1: x = 123, return 321
: Example2: x = -123, return -321
: Have you thought about this?

e****e
发帖数: 418
3
和算法没关吧。我想可能是一旦有错误(overflow)发生,因为不能抛出异常,需要一个
extra parameter来记录错误信息的。例如,extra parameter可以是个List类。

function

【在 f*********m 的大作中提到】
: 题目如下。
: 我的问题:
: 如何理解提示中的最后一句话:“ You would then have to re-design the function
: (ie, add an extra parameter).”加什么样的extra parameter?
: 谢谢。
: 题目:
: Reverse digits of an integer.
: Example1: x = 123, return 321
: Example2: x = -123, return -321
: Have you thought about this?

l*****a
发帖数: 14598
4
why get a list?
大概是这样吧?
bool reverse(int input, int* output,int* error)
{
if(overflow)
{
*error=ERROR_OVER_FLOW;
return false;
}
if(***) {
*error=****;
return false;
}

*output=***;
return true;
}

类。

【在 e****e 的大作中提到】
: 和算法没关吧。我想可能是一旦有错误(overflow)发生,因为不能抛出异常,需要一个
: extra parameter来记录错误信息的。例如,extra parameter可以是个List类。
:
: function

f*********m
发帖数: 726
5
哦,了解,多谢各位。我以为要什么特殊的算法或design pattern。
1 (共1页)
进入JobHunting版参与讨论
相关主题
求教一个, Leetcode 题.请教一个reverse decimal number的问题
Linked电面分享,挺好的题 应该已挂问个简单C reverse int
看atoi代码很麻烦,不如讨论讨论test case吧如何判断一个数是不是回文?
问个越界的问题请假大家一个问题
请教一道Leetcode 题, 多谢问一个reverse int的问题
请问如何安全地reverse 一个integer一道关于两倍年龄的题目 (转载)
reverse an integer 怎么判断是否 overflow 来着有好的merge有序数组算法么
问个简单的atoi的问题帮忙看看我写的atoi有没有bug, 谢谢
相关话题的讨论汇总
话题: integer话题: parameter话题: extra话题: reverse话题: return