Maybe,thank you.
olive
@olive
Posts made by olive

RE: JAVA Cheat Answer #1ms #1linecode easy to understand too
I run the same code, but I get 4ms. Could you tell me why? Thank you.

Something like 89. Gray Code,find the pattern
class Solution { public: vector<int> countBits(int num) { vector<int>res(num+1,0); int base=1; int k=1; while(k<=num){ for(int j=0;j<base&&k<=num;j++) res[k++]=res[j]+1; base<<=1; } return res; } };
like Gray Code, we can find the pattern
0  0
1  1
2  1
3  2
4  1
5  2
6  2
7  3
8  1
Each value of the array [0,2^(i1)1] plus 1 we can get the array [2^(i1),2^i1] .For example,the array[4,7] is array[0,3]+1.

RE: Why it can run 4ms in C++?
I resubmit my second method in c++，I got 4ms. Thank you .

RE: Why it can run 4ms in C++?
I resubmit my second method in c++，I got 4ms. Thank you.

Why it can run 4ms in C++?
int hammingWeight(uint32_t n) { int count = 0; unsigned int temp; for(int i=0; i<32; i++) { temp = n & (1<<i); if(temp > 0) count++; } return count; }
In this code, it must loop 32 times.while in following code, it may be loop less than 32 times.why it just got 8ms? because n>>=1 costs more? Is that right? Hoping you guys help me,thank you.
int hammingWeight(uint32_t n) { int cnt=0; for(;n;n>>=1){ if(n&1)cnt++; } return cnt; }

RE: 0ms C++solution,O(n)time
It seems that your program runs 16ms , how to get 0 ms? or 8ms ? Thank you.

RE: How to get 12ms with C++
I use free(p) to free the memory p at the end, it still costs 16ms.

How to get 12ms with C++
class Solution { public: void deleteNode(ListNode* node) { ListNode* p=node>next; node>val=p>val; node>next=p>next; } };
I can just get 16 ms with c++,how to get 12 ms with c++,can anyone tell me,thanks!