l***4 发帖数: 1788 | 1 leetcode上的divide integer题,小弟的code总是在2147483647, 1这个case上用时过
长,请高手帮忙挑挑bug 拜谢~
code如下:
int divide(int dend, int dor) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
long dividend=dend;
long divisor=dor;
if(dividend==0||divisor==0)
return 0;
int negate=1;
if(dividend<0){
dividend=-dividend;
negate=-negate;
}
if(divisor<0){
divisor=-divisor;
... 阅读全帖 |
|
r******j 发帖数: 92 | 2 我的方法用来数2147483647的位数就不可以,2147483646就可以。哪位知道为什么吗? |
|
r******j 发帖数: 92 | 3 可是2147483647不是java中int可以表示的最大的整数吗?没有overflow吧? |
|
c********t 发帖数: 5706 | 4 目测 似乎有个错 {-2147483648,2147483647} 啥结果? |
|
c********t 发帖数: 5706 | 5 感觉你和ls有一样的错 测测{-2147483648,2147483647}
如果你过了大case, 也许是leetcode没这样的case, 也许是我错了 |
|
d*******3 发帖数: 58 | 6 @recursive 和@fatalme的蠕虫算法好,我试着写了下
struct Tuple
{
int val;
char from;//A,B,or C
};
int MinAbsDiff(vectr& A,vector& B,vector& C)
{
sort(A.begin(),A.end());
sort(B.begin(),B.end());
sort(C.begin(),C.end());
vector D = Merge(A,B,C);
int findCount[3]={0};
int count = 0;
int ans = 2147483647;
for(int start =0,end =0;end < D.length();end++)
{
if(findCount[D[end].from-'A'] == 0)count++:
findCount[D[end].from-'A']++;
... 阅读全帖 |
|
g***j 发帖数: 1275 | 7 Divide two integers without using multiplication, division and mod operator.
这个题目怎么做呀,我用的是数学公式exp(logx - logy)
但是,large set就这一个通不过,难道这个除出来不是-1么?他说expected是0,这是
为什么?
2147483647, -2147483648 -1 0
|
|
r*c 发帖数: 167 | 8 贴个pattern字符串有重复字符的解法, 是dek,cpp1等大牛的解法的扩展。
#include
#include
#include
#include
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
class MinWindowSolution
{
public:
struct TreeNode
{
TreeNode *parent;
int val;
vector children;
TreeNode(int i, TreeNode *p) : val(i), parent(p){}
};
void FindMinWindow_Tree(const vector& input , const vector&
query , int& nStart,... 阅读全帖 |
|
r******l 发帖数: 10760 | 9 你这么算的话,几乎所有问题都可以算是O(1)的了。因为精度有限制,即使O(2^n)这种
指数级的复杂度,其实也不会超过2^2147483647这个常数(假设n是32位整数)。 |
|
h******o 发帖数: 6 | 10 bool helper(TreeNode *node, int min, int max) {
if (node == nullptr) return true;
return node->val < max && node->val > min && helper(node->left, min
, node->val) && helper(node->right, node->val, max);
}
bool isValidBST(TreeNode *root) {
if (root && (root->val == INT_MIN || root->val == INT_MAX)) {
if (!root->left && !root->right) {
return true;
}
}
return helper(root, INT_MIN, INT_MAX);
}
fail {-21... 阅读全帖 |
|
s******3 发帖数: 61 | 11 原先的OJ很容易通过,
public class Solution {
public boolean isValidBST(TreeNode root) {
return rec(root, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
public boolean rec(TreeNode root, int min, int max) {
if (root == null) return true;
if (root.val <= min || root.val >= max) return false;
return rec(root.left, min, root.val) && rec(root.right, root.val,
max);
}
}
但现在OJ加了新的test case,会有
Input: {2147483647}
Output: false
Expected: tr... 阅读全帖 |
|
S*******C 发帖数: 822 | 12 今天面试一个挺高大上的公司,一个韩国面试官让我实现一个HashMap class
我把Entry写成 static inner class
他说应该写成 static inner interface
但HashMap JDK 源代码中的确是写成 static inner class来implement Map.Entry
inner interface的,这个面试官根本没看过源代码,他说要写成static inner
interface的原因仅仅是他找到存在Map.Entry这个interface的api
还有一个问题,我写了一个简洁的hashcode()方法
private int hash(K key){
int hashcode = key.hashCode();
return hashcode > 0 ? hashcode % table.length : -hashcode % table.
length;
}
他说hash怎么可能是负的,为什么要写这个判断语句
实际上
sometimes the hashcode calcul... 阅读全帖 |
|
T*****u 发帖数: 7103 | 13 Leetcode divide two integers
why ???
Submission Result: Wrong Answer
Input:
-2147483648, -1
Output:
2147483648
Expected:
2147483647
|
|
z*****6 发帖数: 29 | 14 Return value定义的是int吧,int范围是-2147483648 ~ 2147483647的。
你的答案其实算是overflow了吧。 |
|
|
n*********u 发帖数: 1030 | 16 正常写python根本不需要管这个,python自动handle int,long。
leetcode直接define个2147483647就行了。 |
|
z*********n 发帖数: 1451 | 17 PhD 有用,越牛越有用,牛PhD会刷题,基本奔着800K(我是本版第一个提出此magic
number的人吗?)去了。
认证的作用是1的话,PhD+刷题 作用大概是2147483647吧。 |
|
|
|
|
|
t*Q 发帖数: 7840 | 22 【 以下文字转载自 sysop 讨论区 】
发信人: tPQ (doji), 信区: sysop
标 题: 神~~
发信站: BBS 未名空间站 (Sun Apr 4 07:20:22 2010, 美东)
veron (贝隆) 共上站 61631 次,发表过 2147483647 篇文章
上次在 [Sun Apr 4 07:17:26 2010] 从 [173.225.] 到本站一游。
离线时间[因在线上或非常断线不详] 信箱:[ ] 身份: [用户]
伪币: [0.00](可用:0.00)
经验值:[0](无人问津) 表现值:[348649](神~~) 生命力:[6666]。
目前在站上,状态如下:
主菜单[2]
没有个人说明档 |
|
c*******o 发帖数: 27734 | 23 哈哈,2147483647 = 7FFFFFFF。看来是溢出了? |
|
M******n 发帖数: 43051 | 24 bug?
veron (贝隆) 共上站 66741 次,发表过 2147483647 篇文章
上次在 [Mon Dec 10 00:17:35 2012] 从 [66.] 到本站一游。
离线时间[Mon Dec 10 00:30:43 2012] 信箱:[ ] 身份: [用户]
伪币: [0.00](可用:0.00)
经验值:[0](无人问津) 表现值:[321932](神~~) 生命力:[6666]。
没有个人说明档 |
|
|
k**l 发帖数: 2966 | 26 或者是个 unique ID counter ?你是有史以来地第 2147483647 个人 |
|
kx 发帖数: 16384 | 27 iMacadamia (aka macadamia) 共上站 18 次,发表过 2147483647 篇文章
上次在 [Wed Jun 17 17:19:17 2009] 从 [71.185.] 到本站一游。
离线时间[Wed Jun 17 18:28:04 2009] 信箱:[信] 身份: [用户]
伪币: [9.70](可用:9.60)
经验值:[0](新手上路) 表现值:[1193046485](神~~) 生命力:[730]。
没有个人说明档 |
|
b*****l 发帖数: 9499 | 28 【 以下文字转载自 Joke 讨论区 】
发信人: bigsail (当年的红帆船), 信区: Joke
标 题: Re: 我操,我的文章数糟糕了 (转载)
发信站: BBS 未名空间站 (Wed Sep 9 12:37:26 2009, 美东)
veron (贝隆) 共上站 9141 次,发表过 2147483647 篇文章
上次在 [Wed Sep 9 12:34:12 2009] 从 [166.111.] 到本站一游。
离线时间[因在线上或非常断线不详] 信箱:[ ] 身份: [用户]
伪币: [0.50](可用:0.00)
经验值:[0](一介白衣) 表现值:[2349320](神~~) 生命力:[6666]。
目前在站上,状态如下:
主菜单[2]
没有个人说明档 |
|
b*****l 发帖数: 9499 | 29 【 以下文字转载自 sysop 讨论区 】
发信人: EUV (白喜欢潇潇雨了,我恨joke版主), 信区: sysop
标 题: Re: 我操,我的文章数糟糕了
发信站: BBS 未名空间站 (Wed Sep 9 14:49:33 2009, 美东)
2^31 -1 = 2147483647
上, |
|
b********e 发帖数: 74 | 30 想重装SQL Server 2005 developer edition. 不知为什么出现错误.无法安装OWC11.
好像是无法安装Office 2003 Web Components. Google了半天也不知道为什么.请教一
下这里的大牛.
=== Verbose logging started: 4/17/2014 20:26:58 Build type: SHIP UNICODE 3
.01.4001.5512 Calling process: C:Program FilesMicrosoft SQL Server90Setup
Bootstrapsetup.exe ===
MSI (c) (04:0C) [20:26:58:156]: Resetting cached policy values
MSI (c) (04:0C) [20:26:58:156]: Machine policy value 'Debug' is 0
MSI (c) (04:0C) [20:26:58:156]: ******* RunEngine:
******* Pro... 阅读全帖 |
|
m******t 发帖数: 2416 | 31
JLS 4.2.1: "For int, from -2147483648 to 2147483647, inclusive". |
|
b******a 发帖数: 215 | 32 2147483647和3147483647换成string,是不是一样的位数?
但是后面那个数已经超出32bit int的范围了. |
|
g*********s 发帖数: 1782 | 33 【 以下文字转载自 JobHunting 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: JobHunting
标 题: 经典题atoi的溢出处理
发信站: BBS 未名空间站 (Tue Feb 22 21:40:03 2011, 美东)
int atoi(const char* s);
assuming INT_MAX = 2^31-1, INT_MIN = -2^31, the following must hold:
atoi("2147483648") = 2147483647
atoi("-2147483649") = -2147483648
but this seems a little tricky. any elegant solution to handle the
overflow? |
|
k**********g 发帖数: 989 | 34
Firstly, signed and unsigned int have a "common interval".
From zero to INT_MAX (0 .. 2147483647)
When both operands are within this common interval, comparison result will
be correct regardless of each operand's type, and/or the coercion rule.
Therefore, one only needs to check that each operand's value is within this
common interval (prior to coercion). This is how the machine code is
typically generated in languages that have integer range checking.
It is very simple to test this. Just test ... 阅读全帖 |
|
k**********g 发帖数: 989 | 35
Firstly, signed and unsigned int have a "common interval".
From zero to INT_MAX (0 .. 2147483647)
When both operands are within this common interval, comparison result will
be correct regardless of each operand's type, and/or the coercion rule.
Therefore, one only needs to check that each operand's value is within this
common interval (prior to coercion). This is how the machine code is
typically generated in languages that have integer range checking.
It is very simple to test this. Just test ... 阅读全帖 |
|
l******9 发帖数: 579 | 36 我不是这个 application 的开发人。
我知道 REST and SOAP.
但是不知道如何在代码里区分它们, REST 只是一种 architectural style。 SOAP
只是一种 protocol 。
我的 application service (published by IIS 7。5 to my desktop)
发布成功后, 交给用户的是一个 URL 指向我的 desktop 的一个文件夹。
用户可以从这个链接 下载并安装 这个 application 工具。 这个工具 有GUI, 可以
从的指向的文件夹 下载文件。
但是, 文件大于 64KB 就不能下载 或者只下载 64KB。
I got error:
connection was forcibly closed by remote server
on my laptop (client side), and
error 504 gateway timeout
on my desktop (server side).
我在IIS 7.5 manager, ASP property 里面 更改了
... 阅读全帖 |
|
|
o****e 发帖数: 536 | 38 Problem statement:
We often use a phase locked loop capable of generating a new frequency which
is locked in
phase to a clock that is supplied at a different frequency. The relationship
between the two
frequencies is given by a rational fraction - that is, there is a
multiplication step and a
division step, both of which are integers, to convert from one frequency to
the other.
For example, we may have a 10 MHz clock, and we need a 12 MHz clock which is
phase
locked to the 10 MHz clock. In this ... 阅读全帖 |
|
h**********c 发帖数: 4120 | 39 D:\indexpermutation\Debug>indexpermutation
Signed int min: -2147483648 max: 2147483647
total: 253955520
====1,2,3,4,5,6,7,
44__8__-14
7__-18__23__26
-13__22__1__2__26
26__3__4__5
25__6__7
EQ1: 38
EQ2: 38
EQ3: 38
EQ4: 38
EQ5: 38
EQ6: 38
EQ7: 38
EQ8: 38
EQ9: 38
EQ10: 38
EQ11: 38
EQ12: 38
EQ13: 38
EQ14: 38
EQ15: 38 |
|
h**********c 发帖数: 4120 | 40 1到P^7_{19}的全部解:
D:\indexpermutation\Debug>indexpermutation
Signed int min: -2147483648 max: 2147483647
total: 253955520
Progress 10000000:
True 18064122
Results
15,13,10,14,8,
4,12,9,6,5,
2,16,11,1,7,
19,18,17,3,
True 19273415
Results
15,14,9,13,8,
6,11,10,4,5,
1,18,12,2,7,
17,16,19,3,
Progress 20000000:
Progress 30000000:
Progress 40000000:
Progress 50000000:
Progress 60000000:
Progress 70000000:
Progress 80000000:
True 87367097
Results
16,12,10,19,2,
4,13,3,7,5,
8,15,17,1,6,
14,18,11,9,
True 8 |
|
b********r 发帖数: 7843 | 41 早抓住了,而且已经正法了
iMacadamia (aka macadamia) 共上站 18 次,发表过 2147483647 篇文章
上次在 [Wed Jun 17 17:19:17 2009] 从 [71.185.] 到本站一游。
离线时间[Wed Jun 17 18:28:04 2009] 信箱:[信] 身份: [新人]
伪币: [9.70](可用:9.60)
经验值:[0](新手上路) 表现值:[1193046485](神~~) 生命力:[29]。
没有个人说明档 |
|
t*Q 发帖数: 7840 | 42 veron (贝隆) 共上站 61631 次,发表过 2147483647 篇文章
上次在 [Sun Apr 4 07:17:26 2010] 从 [173.225.] 到本站一游。
离线时间[因在线上或非常断线不详] 信箱:[ ] 身份: [用户]
伪币: [0.00](可用:0.00)
经验值:[0](无人问津) 表现值:[348649](神~~) 生命力:[6666]。
目前在站上,状态如下:
主菜单[2]
没有个人说明档 |
|
|
|
w*******y 发帖数: 60932 | 45 Diapers.com
Today's Deal - 25% off Carter's Multi-Pack Bodysuits.
CartersBodyS uits:
http://www.diapers.com/product/subcategory.aspx?categoryid=9&categoryname=Clothing & Shoes&subcategoryid=182&subcategoryname=Bodysuits&queryfrom=subcategory&filtername=Type|Brand&filtervalue=Multi-pack Bodysuits|Carter's&PageSize=2147483647
Use code FBOCTCARTERS at checkout for 25% off
Add a filler for $0.19c from soap.com and get free shipping on $25 before
the coupon code
VicksCoughDr ops:
http://www.soap.co... 阅读全帖 |
|
w*******y 发帖数: 60932 | 46 Sunday Only!
Buy one Robeez item, get one for 50% off.
Use code FBROBEEZ at checkout.
Valid for 10/31/2010 only while promotional supply lasts.
Cannot be combined with any other offer.
Robeez Shoes:
http://www.diapers.com/product/category.aspx?categoryid=9&categoryname=Clothing & Shoes&queryfrom=category&filtername=Brand&filtervalue=Robeez&PageSize=2147483647&SortExpression=Price (Ascending)
Select the 2 pairs you want add them to your cart then add the filler from
soap.com below to get free shi... 阅读全帖 |
|
|
|
w*******y 发帖数: 60932 | 49 50% off Febreze at Soap.com.
Use code FBFEBREZE at checkout.
Max discount $10
Febreze Products:
http://www.soap.com/product/category.aspx?categoryid=66&categoryname=Household Products&queryfrom=category&filtername=Brand&filtervalue=Febreze&PageSize=2147483647&SortExpression=Price (Ascending)
Valid 12/22/2010 only, while supplies last. .
Cannot be combined with any other offers. Other restrictions apply.
|
|
w*******y 发帖数: 60932 | 50 50% off Clif Bar at Soap.com.
Use code FBCLIF at checkout.
Max discount $10
Clif Products Link:
http://www.soap.com/product/category.aspx?categoryid=74&categoryname=Diet & Fitness&queryfrom=category&filtername=Brand&filtervalue=Clif&PageSize=2147483647&SortExpression=Price (Ascending)
Free shipping @ $25 pre-coupon
Valid 12/28/2010 only, while supplies last.
Cannot be combined with any other offers. Other restrictions may apply
Examples:-
6 x 6 packs (36 total) of Clif Kid Z Bar:
http://www.soap... 阅读全帖 |
|