So Below code works fine on my local IDE, where I also list my unit test results.

I got MLE error when OJ tests findNthDigit(10000000).

I originally guess it is because I count too many local vars pos_start and pos_end, so I use a hashmap to store previously calculated results and use them to calculate the new round, but still failed with MLE error.

I am not from CS background, so I don't understand where my code could have a MLE? and why I could pass local IDE test if there is any error that not accepted by OJ?

Thanks!

```
import math
class Solution(object):
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
pos_HashMap = {0:1}
for e in xrange(1, int(math.log( (2**31 - 1), 10)) + 1): # find which group n is in
pos_start = pos_HashMap[e-1] + 9 * (int(10 ** ((e-1) - 1)) * (e-1))
pos_HashMap.update({e: pos_start})
# pos_start = sum([9 * (10 ** (i - 1) * i) for i in xrange(1, e)]) + 1 # this group's start and end position
pos_end = pos_start + 9 * (10 ** (e - 1)) * e - 1
if n in range(pos_start, pos_end + 1): # if n in this position interval
num_start = 10 ** (e - 1) # find this group's start value
n_val_tgt = (n - pos_start)/e + num_start # find n's real value and return its digit
n_val_rm = (n - pos_start)%e
return int(str(n_val_tgt)[n_val_rm])
if __name__ == '__main__':
print Solution().findNthDigit(10000000) # 7
# print Solution().findNthDigit(3) #3
# print Solution().findNthDigit(9) #9
# print Solution().findNthDigit(11) #0
# print Solution().findNthDigit(28) #1
# print Solution().findNthDigit(100) #5
```