-
Notifications
You must be signed in to change notification settings - Fork 19
[python] unlimited integer range and find duplicated number in array
Myungchul Shin edited this page Aug 9, 2016
·
6 revisions
-
question
-
unlimited integer range of python
import sys
print type(sys.maxint) # sys.maxsize for python3
print sys.maxint
print '0x%X' % (sys.maxint)
print type(sys.maxint + 1)
print sys.maxint + 1
print '0x%X' % (sys.maxint+1)
i = (1 << 63)
print type(i)
print i
print '0x%X' % i
nums = [n+1 for n in xrange(400)]
nums.append(35)
print nums
tmp = 0
for n in nums :
if ((1 << n) & tmp) != 0 :
print 'found = ',n
tmp |= (1 << n)
print type(tmp)
<type 'int'>
9223372036854775807
0x7FFFFFFFFFFFFFFF
<type 'long'>
9223372036854775808
0x8000000000000000
<type 'long'>
9223372036854775808
0x8000000000000000
[1, 2, 3, ... 399, 400, 35]
<type 'int'>
<type 'int'>
<type 'int'>
...
<type 'long'>
<type 'long'>
<type 'long'>
...
<type 'long'>
found = 35
<type 'long'>
- reference : http://stackoverflow.com/a/9860611
- however, how can we find duplicated number using other programming language?