class Solution(object):
checkPerfectNumber = {6, 28, 496, 8128, 33550336}.__contains__
StefanPochmann
@StefanPochmann
No, seriously, my name really is Stefan. Not Stephan, Stephen, Steven or even Stefen.
Posts made by StefanPochmann

RE: Simple Python

RE: Java O(1) space and O(n^2*logn)
It's really not O(n log n), though. Because your strings get longer and longer, making the string operations more and more expensive. It does look like O(n^{2}) to me. And here's an experiment, testing n=2^{10} to n=2^{17}
public static void main(String[] args) { for (int n = 1 << 10; n <= 1 << 17; n *= 2) { long t0 = System.nanoTime(); new Solution().findContestMatch(n); long t1 = System.nanoTime(); System.out.println(String.format("%7.3f", (t1  t0) / 1e9)); } }
The results:
0.035 0.087 0.274 0.985 4.001 15.985 63.948 260.918
Doubling of n clearly causes roughly a quadrupling in time, agreeing with Θ(n^{2}) complexity.

RE: oneliner Ruby + Python
@ysonglc It means "ignore case". Look for
(?aiLmsux)
on that documentation page. 
2 lines Python
We can leverage that Python already has complex numbers and can
eval
expressions.def complexNumberMultiply(self, a, b): z = eval(('(%s)*(%s)' % (a, b)).replace('i', 'j')) return '%d+%di' % (z.real, z.imag)
Edit: Oh well, turns out it's not much work to calculate it myself:
def complexNumberMultiply(self, a, b): a, ai, b, bi = map(int, re.findall('?\d+', a+b)) return '%d+%di' % (a*b  ai*bi, a*bi + ai*b)

RE: C#  O(n) time and O(n) space  simple 2 pointer
I don't think it's O(n) time but only O(n log n). You first build n strings of "length" 1 (meaning one team), costing n time. Then you build n/2 strings of length 2, costing (n/2)*2 = n time. Then you build n/4 strings of length 4, costing (n/4)*4 = n time. And so on. Each round costs n time, and you have log(n) rounds.

RE: Teamwork in Contests
@cuiaoxiang Yes, as described I picked two minutes as the bar. The reason was that with three minutes, I would've had to analyze 12 or 13 more people, and I didn't feel like doing that. I felt four people would be enough. And yes, while I already analyzed more deeply than @yorkshire, one can of course look even more deeply. Thank you for doing that and pointing out that the top ten competitors all had similarly fast times for that problem. Sorry if you feel that it was rude to post user IDs. I don't think it was. I think it just makes communication easier. Not sure why you're telling me what you would do if you strongly suspect someone is cheating. I don't suspect anyone of cheating, let alone strongly. As I already explicitly said, it doesn't look like teamwork to me. But I'll add another note up there to prevent confusion. I was hoping the data would speak for itself, but apparently it doesn't.
@awice Thanks for your response as well, good to see further explanation. As I already said, what you were doing rather looked like a strategy to me (instead of teamwork). Partly because your overall statistics don't look suspicious to me, but mostly because I already knew you from many good posts from you on this forum. I had actually thought you maybe held back the submission in order to not give others a clue how easy the first problem is, but your actual reason makes even more sense.

Missing test cases
The following wrong code gets accepted:
def checkPerfectNumber(self, num): k = num.bit_length() / 2 return num > 1 and num == (2 << k)  1 << k
It just checks whether the number has a certain form (k+1 onebits followed by k zerobits). That form is necessary (at least for numbers in the allowed range, see Wikipedia) but not sufficient. It incorrectly returns
True
for the following numbers, so those should be added to the test suite:120, 2016, 32640, 130816, 523776, 2096128, 8386560

RE: Short easy C++ using set
@knowledge2thepeople said in Short easy C++ using set:
I don't think using a set in the way that you are in your solution is consistent with the spirit of this question.
Why not?

RE: Python O(1) space solutions
@vhquang There are only two vectors, not m.