Redian新闻
>
今天底点过了吧? around 13:10pm
avatar
今天底点过了吧? around 13:10pm# Stock
m*r
1
public int isPowerOfTwo(int x)
{
return(
x == 1 || x == 2 || x == 4 || x == 8 || x == 16 || x == 32 ||
x == 64 || x == 128 || x == 256 || x == 512 || x == 1024 ||
x == 2048 || x == 4096 || x == 8192 || x == 16384 ||
x == 32768 || x == 65536 || x == 131072 || x == 262144 ||
x == 524288 || x == 1048576 || x == 2097152 ||
x == 4194304 || x == 8388608 || x == 16777216 ||
x == 33554432 || x == 67108864 || x == 134217728 ||
x == 268435456 || x == 536870912 || x == 1073741824 ||
x == 2147483648);
);
}
这种算O(1)吧,算是最快了吗?
avatar
A*k
2
anyone can confirm?
load 3x etf near 13:10pm
avatar
r*l
3
你这么算的话,几乎所有问题都可以算是O(1)的了。因为精度有限制,即使O(2^n)这种
指数级的复杂度,其实也不会超过2^2147483647这个常数(假设n是32位整数)。
avatar
p*i
4
股神啊
avatar
j*3
5
这个看起来有点。。。。有点恶心
avatar
A*k
6
load some SPY and some UPRO
BOT 200 SPY Stock 119.450 USD ISLAND 10:08:45 1.
00
BOT 100 SPY Stock 119.4499 USD SMART 10:10:59 1.
00

【在 A******k 的大作中提到】
: anyone can confirm?
: load 3x etf near 13:10pm

avatar
m*r
7
谢谢上面的回复
要是这样写呢?这样写O(n)我直接不会说了
public in isPowerOfTwo(int x)
{
while (((x & 1) == 0) && x > 1)
x >>= 1;
return (x == 1);
}
avatar
b*r
8
false bottom confirmed..
avatar
e*i
9
(x & (x-1)) == 0

【在 m**r 的大作中提到】
: public int isPowerOfTwo(int x)
: {
: return(
: x == 1 || x == 2 || x == 4 || x == 8 || x == 16 || x == 32 ||
: x == 64 || x == 128 || x == 256 || x == 512 || x == 1024 ||
: x == 2048 || x == 4096 || x == 8192 || x == 16384 ||
: x == 32768 || x == 65536 || x == 131072 || x == 262144 ||
: x == 524288 || x == 1048576 || x == 2097152 ||
: x == 4194304 || x == 8388608 || x == 16777216 ||
: x == 33554432 || x == 67108864 || x == 134217728 ||

avatar
T*s
10
bulls are happy to buy every dip then MM are happy
avatar
n*n
11
有才
avatar
C*G
12
今天多了几个苹果?
hoho

【在 T*********s 的大作中提到】
: bulls are happy to buy every dip then MM are happy
avatar
m*k
13
should add: x != 0

【在 e*****i 的大作中提到】
: (x & (x-1)) == 0
avatar
T*s
14
yes :) MM returned my apple
no interest yet :(

【在 C*G 的大作中提到】
: 今天多了几个苹果?
: hoho

avatar
s*k
15
干嘛不弄个数组放进去。。。

【在 m**r 的大作中提到】
: public int isPowerOfTwo(int x)
: {
: return(
: x == 1 || x == 2 || x == 4 || x == 8 || x == 16 || x == 32 ||
: x == 64 || x == 128 || x == 256 || x == 512 || x == 1024 ||
: x == 2048 || x == 4096 || x == 8192 || x == 16384 ||
: x == 32768 || x == 65536 || x == 131072 || x == 262144 ||
: x == 524288 || x == 1048576 || x == 2097152 ||
: x == 4194304 || x == 8388608 || x == 16777216 ||
: x == 33554432 || x == 67108864 || x == 134217728 ||

avatar
n*s
16
x > 0

【在 m*****k 的大作中提到】
: should add: x != 0
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。